DIV's vs. Tables or CSS vs. Being Stupid

CssLayout

Css Problem Overview


I know that tables are for tabular data, but it's so tempting to use them for layout. I can handle DIV's to get a three column layout, but when you got 4 nested DIV's, it get tricky.

Is there a tutorial/reference out there to persuade me to use DIV's for layout?

I want to use DIV's, but I refuse to spend an hour to position my DIV/SPAN where I want it.

@GaryF: Blueprint CSS has to be the CSS's best kept secret.

Great tool - Blueprint Grid CSS Generator.

Css Solutions


Solution 1 - Css

There's the Yahoo Grid CSS which can do all sorts of things.

But remember: CSS IS NOT A RELIGION. If you save hours by using tables instead of css, do so.

One of the corner cases I could never make my mind up about is forms. I'd love to do it in css, but it's just so much more complicated than tables.

You could even argue that forms are tables, in that they have headers (labels) and data (input fields).

Solution 2 - Css

In the UK and in US there is a legal requirement for favouring CSS layouts over Tables. Both Section 508 (US) and the Disability Discrimination Act (UK) cover accessibility standards for users with limited vision.

In the UK the legislation extends so far as to actually make it illegal to commercially produce a site that impedes the ability of a partially sighted user in the same way that it is now illegal to have a shop with a step to enter it and no way for a wheelchair user to get in - admittedly there have been no prosecutions over website accessibility yet. However I would always go with CSS as it means that your site design is so much easier to maintain in the longer term.

Investing time in learning CSS (I used W3C schools and .Net Magazine http://www.netmag.co.uk) will pay off.

Solution 3 - Css

Solution 4 - Css

In my opinion, the bias should be in favour of CSS over IE6 - i.e. unless there's an insanely good reason (e.g. your site is only targetted at people using IE6, which would be weird), it's better to 'alienate' people using IE6 rather than people with poor vision and/or automated user agents. Usage of IE6 is decreasing; the latter group is increasing in number. Even if your site doesn't look perfect in IE6, it will probably be easy for those users to read it than a table-based layout will for those who can't see it.

This is a very general question, so it's difficult to answer with specifics. The two books that are excellent resources are:

If you only have to spend an hour designing your overall site layout, that's not bad going.

Solution 5 - Css

CSS may not be a religion, but it is how browsers interpret HTML for layout. Like it or not, all modern browsers use (some version) of the W3C box model. To continue to rely on tables is continue to rely on a methodology that is just plain wrong in the eyes of the people who design web rendering technology.

I know CSS can seem awfully complicated at times, but I believe it is a necessity in this day and age (trust me, your clients are going to want it).

If you don't feel comfortable taking the time really learn CSS (so it takes you seconds or minutes to position elements...not an hour), then you need to pass the layout work on to someone who knows really knows the front-end.

Yes, there are a lot of problems with the current browser implementations of CSS, but nothing so drastic that you should ever feel the need to return to table based layout. Just sit down and take the time to learn it, like you would any other language or framework.

The best online reference resource I've found is this one: http://reference.sitepoint.com/css

But it might not hurt to look at a book like Designing With Web Standards which goes a long way in helping you to understand why this stuff is important.

Solution 6 - Css

I was also thinking Blueprint was great until I saw YAML (Yet Another Multicolumn Layout). There is an online builder tool which is fantastic. I can get a cool looking multicolumn layout within 5 mins.

Solution 7 - Css

After a while you don't even think about it. Using divs with CSS seems like the easier option imo. Plus, you have more freedom when using frameworks such as jQuery. I couldn't imagine doing some of the cool jQuery stuff without using css or divs. If you use tables for style and layout I feel like you miss out on a lot of new technologies and stay stuck in the 90's.

Solution 8 - Css

This may be unhelpful but I somehow don't understand all these problems related to CSS. If a newspaper designer would try to embed a movie in the ad page, everybody would agree that he's a bit crazy. But still those same people pine after three-column layouts in HTML. HTML is just not apt to handle this kind of layout well at the moment. Furthermore, multi-column layouts are generally not really well-suited for reading on computer monitors. Aren't there enough viable alternatives?

And by the way, even tables don't offer a good way of implementing a fluent column layout so this is no reason at all to resort to such hacks. Assuming a halfway modern browser (i.e. > MSIE 6), tables don't offer any advantages over clean HTML + CSS that I know of.

Solution 9 - Css

I would just use the table.

In my experience, using a table for layout will work the same in all browsers and the CSS will not (especially if you're trying to support IE6). It's just not worth the hours and hours of coding to get a layout to work in CSS when it can be done in 10 minutes using a table.

The other advantage to using tables is that your layout can very easily dynamically size itself to content. Trying to get that done with CSS is a huge nightmare.

Solution 10 - Css

I find there are lots of limitations to CSS that just seem to hint the specification designers don't make websites for a living.

Use HTML tables if you can't do it easy in CSS.

Having said that, some of the frameworks do help and it always nicer to do in CSS if you can manage it.

Solution 11 - Css

You might be able to find some inspiration here: http://blog.html.it/layoutgala/

Solution 12 - Css

A List Apart is a great reference for using semantic HTML, the Holy Grail article is probably one of the best examples. Also, check out CSS Zen Garden for some inspiration on the topic or read Dave Shea's excellent book "The Zen of CSS Design."

Solution 13 - Css

You use CSS for layout because not only is it semantically correct but because tables have multiple drawbacks.

Tables are horrible for accessibility because they break almost all screen readers, which in turn gives the visually impaired worthless information because of the way the tables are read.

They also render much slower than their CSS counterparts. Tables have to be drawn twice, once for the layout, and again for the content. This can mean that if you have a remote image or two on a server with a slow connection that your ENTIRE LAYOUT will not render.

Would you use an array to store a dictionary when you have a hashmap? No. And you shouldn't use a table when there's something out there which works better.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionroman mView Question on Stackoverflow
Solution 1 - CssMatthias WinkelmannView Answer on Stackoverflow
Solution 2 - CssMauroView Answer on Stackoverflow
Solution 3 - CsshuseyintView Answer on Stackoverflow
Solution 4 - CssBobby JackView Answer on Stackoverflow
Solution 5 - CssBryan M.View Answer on Stackoverflow
Solution 6 - CsscnuView Answer on Stackoverflow
Solution 7 - CssSpencer CooleyView Answer on Stackoverflow
Solution 8 - CssKonrad RudolphView Answer on Stackoverflow
Solution 9 - Css17 of 26View Answer on Stackoverflow
Solution 10 - CssMatt MitchellView Answer on Stackoverflow
Solution 11 - CsserlandoView Answer on Stackoverflow
Solution 12 - CssEric DeLabarView Answer on Stackoverflow
Solution 13 - CssGregoryDView Answer on Stackoverflow