Forum Moderators: open

Message Too Old, No Replies

DIV vs TABLE

         

DrDoc

8:55 am on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have to admit that the development here on Webmaster World pleases me. I'm very glad to see that so many people consider using DIVs over the old fashion table alternative. Lots of users are making the transition from HTML to XHTML, which is indeed a very wise move on their part.

However, this transition and change causes more than a few problems. It is easy to replace a simple table layout with DIVs. But it is very easy to get caught up in the DIVs and CSS.

Using DIVs and CSS you can make the page look exactly the way you want, with less code bloat than the old TABLE layout. But sometimes I have seen examples posted on here where the developer has added a zillion DIVs, nested in a complicated way that makes the code hard to update and almost impossible to read.

I'm not saying that you shouldn't use DIVs. I'd use them over tables any day. But it is important to be careful.

If you are leaving the table layout, remember the full power of CSS. It is wise to make use of absolute positioning as well as float attributes for individual elements within the DIVs. Another property worth remembering is clearing the float.

There are lots of very useful examples here. I admit that there are times when a complicated layout is the only solution. But before resorting to a jungle of DIVs, try to see if there's a simpler solution. Look for examples here on Webmaster World.

It will save you a couple of gray hairs later. ;)

Birdman

10:04 am on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very good point, DrDoc. I made the switch to XHTML w/ CSS not too long ago myself. I am very happy I did, too. Much easier layout and faster loading, validating pages. I have caught myself getting a little crazy with nested <div>s to the point that I asked myself "Isn't this the reason I quit tables in the first place?".

>>>. Another property worth remembering is clearing the float.
Could you explain this property?

Birdman

papabaer

12:49 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just as there were and still exist, elegant table layouts (yes... I said it!), unfortunately, there are far too many that nest table within table within table.

Enter CSS. Developers now have a toolbox that provides a means to create fast loading, lightweight pages. Some have taken the simplicity to heart and are designing stylish pages using only a fraction of the code previosly required.

Others, like over-eager, eyes-bigger-than-their-stomachs, gluttons in a buffet line heap every possible flavor and CSS dainty onto their many plates until each overflows with a mish-mosh that is both hideous and certain to cause severe indigestion.

And just as simply knowing HTML does not ensure a good "designer," neither does knowing CSS. Some, new to the concept will undoubtably mature in the process and hone their design skills and refine their personal CSS toolbox. Others will not. Life goes on... ;)

papabaer

12:53 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another property worth remembering is clearing the float...

[w3.org...]

rewboss

1:56 pm on Jul 14, 2002 (gmt 0)

10+ Year Member



The CSS float property basically replaces HTML align in <img> and <table> tags. So instead of

<img align="left">

you can write

img { float: left; }

It detatches it from its "natural" position in the document flow, and allows it to "float" towards the left (or right, if you've specified right) as far as it goes -- usually to the border of the containing element, unless there is another floated object in the way. Content then "flows" around it.

Related to that is the clear property, which replaces <br clear="left" /> (or "right" or "all"). This places the element at the first available position where the specified border(s) of the containing element is/are clear -- i.e. no floated objects in the way.

copongcopong

11:02 pm on Jul 14, 2002 (gmt 0)

10+ Year Member



for me i, find div tags more logical and more intuitive than table tags (tr and td).

unfortunately, browser do need to catch up so that they would display the divs (and its positioning) correctly and perfect unlike tables.

well, float is one cool feature of css.

brotherhood of LAN

11:17 pm on Jul 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm at the pearly gates of all this. For a simple minimal site, it will be a case of <divs> and <h> tags, with the rest going into CSS.

I think during my time at WMW I have the same content running on a bout half as much code..and its still getting whittled down.

This is definetely something I want to get hands on with.