tags:

views:

2652

answers:

13

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.

+1  A: 

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.

Konrad Rudolph
Except HTML can handle it. What can't handle it is CSS.
Graphain
Can you be more specific? Exactly what can't CSS handle?
Bobby Jack
Konrad mentioned "three-column layouts" cannot be achieved in HTML. Tables very easily achieve this. It is a similar story with 100% height elements and vertical alignment. CSS tends to fail hard in these situations and rather than working the standard to how people work they criticise the design.
Graphain
I believe the standard **is** being enhanced - the "advanced layout module" of css3 (http://www.w3.org/TR/css3-layout/) will give us much of what we require here. Granted, it will be some time before CSS3 is widely supported. K only said that 3-column layouts cannot be achieved "WELL" in HTML.
Bobby Jack
CSS can handle multi column layouts very well. You people assume that multi columns means "a single article, split up into multiple columns" (just like your daily newspaper), but that's not it. The standard page design is, nav|content|etc - that's multiple columns as well and CSS can handle that.
Till
Yes, but CSS can't handle what people assume well.CSS shortsightedness is always explained away by blaming the developer.CSS is always nicer when it works, but I don't like advocates blaming the developer for trying to do something that users want.
Graphain
Graphain, my point was *exactly* that CSS can handle the same as tables. Granted, multi-column layouts require some hacks but are possible. However, both CSS and tables fail at breaking continuous text into multiple columns (although there are hacks in CSS/JS to do even this).
Konrad Rudolph
http://www.youtube.com/watch?v=UaMdYrNVLG0 - this newspaper's designer "is a bit crazy"...
Vili
@Vili: They’re crazy all right. They are using it for ads! … and this just goes to show how quickly established truths become obsolete in technology. Duh. Someone hand me a new example please … how ’bout Flash games in newspapers?
Konrad Rudolph
+30  A: 

If you want to do the right thing AND have most of the work done for you, I'd highly recommend Blueprint CSS. It's a good blend of the best practices we've been seeing over the years, and pragmatic design decisions. It's also good pretty good grid layout functionality. Give it a look.

GaryF
WOW ... I love the idea !!! Thank you!
roman m
muchas gracias my friend, this is excellente! +1
Ric Tokyo
+1 960 grid is also very good
Paul
+17  A: 

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).

MattW.
Strictly speaking, a form is (almost) never a table. What would be the column heading for the data - "input fields"? By that argument, you could claim anything is a table: a paragraph is a single-celled table... Form support is pretty nasty, mainly because browser-manufacturers disagree on stuff
Bobby Jack
I'd argue the labels are the headers. There is even an argument to th to specify a horizontal arrangement IIRC
MattW.
OK, but a set of data with a single row of headers and a single row of data is semantically closer to a definition list than a table.
Bobby Jack
Another vote for dl instead of tables for forms
Slartibartfast
There are a number of table-less ways to markup forms, all of which produce leaner markup which also works better in screen readers. Check out http://wufoo.com/ for some examples.
Sam Murray-Sutton
@MattW. CSS is not a religion? speak for yourself. @import('god'). :D
Paul
A: 

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.

17 of 26
A: 

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.

Graphain
+6  A: 

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.

Bobby Jack
+9  A: 

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.

Mauro
The same is true in Germany – but only for federal office websites.
Konrad Rudolph
+1  A: 

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

erlando
+7  A: 

Why tables for layout is stupid: problems defined, solutions offered.

huseyint
i saw this a while ago, wanted to link it up in a question, but couldn't find it
roman m
And to think was for Seybold in 2003 and people are still arguing for tables!
Jon P
+5  A: 

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.

Bryan M.
+4  A: 

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.

cnu
+1  A: 

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."

Eric DeLabar
+1  A: 

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.