Jump to content

What to use, tables, divs or...?


Chappers

Recommended Posts

Hi everyone,

 

After years of using tables, I'm having a mid-table crisis. It was after coming across this problem again:

 

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="2">
<p class="text">Hello world.</p>
<p class="text">And hello again in a new paragraph block.</p>
</td>
</tr>

<tr>
<td><p class="text">I want to show you a picture.</p></td>
<td width="110" align="center"><img src=gimp.jpg"></td>
</tr>

<tr>
<td colspan="2">
<p class="text">More text.</p>
</td>
</tr>
</table>

 

Now the trouble with the above: With just one <td> and all the text contained within different paragraphs <p></p> there is an empty line between each paragraph, separating them neatly.

 

Since I want images at the side of some paragraphs, it means I have to do what the code above shows - end the initial <td> and create others so the image can go in its own. Trouble with that is that the neat gaps between paragraphs is lost and the text just displays in one large block. To add a space between paragraphs, I have to add <br> at the end of a paragraph before closing the <td> and beginning the next. That leaves a much bigger gap than the <p> normally gives and so looks bad.

 

I can't see a way around it, so I got looking into divs again, even though I'd been warned before not to use them. I can't yet remember how to use them to display the code above as I'd want it, but regardless, is it the best way to go?

 

Or is there an alternative to tables and divs? What's best?

 

Someone please help!

 

Thank ye,

James

Link to comment
Share on other sites

what someone said dont use divs?

 

ive never heard that and wnet to divs as soon as it seemed possible to run on only divs and never even thought about looking back

 

 

divs are way better then tables imo

 

but you could just add

this to your p class

 

in stylesheet

 

p.text {margin-bottom:5px;}

and adjust the height to your needs and then no need for the br tag as you get a controlable gap at the bottom of your p

Link to comment
Share on other sites

okay in the end this will give you a hell of a lot more control using css and divs instead of tables..

i just did a quick mock up of what you had for code


<style>
div.wrapper {width:100%;}
div.full {width:100%;}
div.text {width:75%;float:left;text-align:left;}
div.image {width:24%;float:right;}
p.text {padding:0;margin:0;}
</style>


<div class="wrapper">
<div class="full">
	<p class="text">Hello world.</p>
	<p class="text">And hello again in a new paragraph block.</p>
</div>
<div class="text">
	<p class="text">I want to show you a picture.</p>
</div>
<div class="image">
	<img src="4.png" />
</div>
<div style="clear:both;"> </div>
<div class="full">
	<p class="text">More text.</p>
</div>


</div>


Link to comment
Share on other sites

Tables should never be used for formatting, only for displaying Tabular Data.

 

That is my opinion at least.

 

I think that's general consensus by now.

Its also been the w3c standard for at least 6 years, so it should be everyone's consensus.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.