tags:

views:

232

answers:

9

I know there are various good arguments preferring css positioning over table-based layouts. What I'm wondering is whether the CSS model is complete (assuming a relatively modern browser) with respect to ALL of the capabilities of tables. Are there layouts that tables can achieve that are impossible or impractical with CSS?

+4  A: 

Tables are meant and should be used for tabular data, and not for structure. Personally I see tables being used as an easy way out, and I have never ran into a situation that could not be solved with CSS.

Tables are definitely easier for vertical positioning and full height columns, but again this can be overcome with CSS.

Dustin Laine
I am not one who advocates cutting corners in programming but there are cases where a "hack" is just better than doing something the "ideal" way. Html tables work. In every browser. Always. They are simple to understand and maintainable. CSS is the opposite of this when it comes to laying out divs.
Nemi
@Nemi - Boo! Then what are standards for?
Dustin Laine
+-0 I respectfully disagree. There *are* situations that cannot be handled without either tables or JavaScript. The designers of the CSS standard did a poor job in providing alternatives to `table` for use in layouts - why, I do not know. As for "the easy way out", I put it to you that when the choice is between a five-line `<table>` construct, or 80 lines of CSS plus three browser-specific hacks for IE6 and 7 and maybe 8, plus a block of JavaScript because (Safari|Opera|xyz) don't support this and that pseudo-class, the "easy way out" is indeed the right way.
Pekka
A: 

Terrible looking ones?

Seriously, though. No.

A good example of people using tables is that they make it a lot easier to present form fields in a nice looking way but it completely messes with accessability and semantic meaning of pages. You can acheive the same and better with a little more effort in CSS.

Rob Stevenson-Leggett
A: 

You can do the same thing with CSS, but it isn't usually as elegant.

Tables are important to display tabular data (i.e., NOT LAYOUTS) . They are logical, semantic constructs and should be used as such. They contains concepts like columns and rows, that CSS alone does not.

Diodeus
I am not sure I buy the argument "they are for TABULAR" data. You realize that http/html is meant for STATIC content, right? And that web apps and saving state in sessions is a perversion of that, right? Using a tool for something because it works well, even when it wasn't originally made for that use is not wrong. It is just smart.
Nemi
With your logic Nemi, we should still be using online FONT statements and spacer GIFs. Not only has the technology evolved, but so has the THINKING on how to use this technology. Sure you CAN use tables for layout, and you can also pound in nails with a ROCK.
Diodeus
A: 

save you time

Anurag
at what sacrifice?
Dustin Laine
glad to see that you agree with my answer
Anurag
+1  A: 

I got one! There is something that seems to me impossible with css, but is possible with tables. I just asked a question on this yesterday and got an answer.

If you have two separate elements that you want on one line, regardless of width, you must use a table. That is, if the two elements are either inline or floated, if they are dynamically sized and become wider than the container, they will break to the next line rather than overflow. If you absolutely require that they stay on the same line even if the second one would overflow the container's width, then they need to be cells in a table row.

edit: a bit of testing shows this is only true with floats. If your elements are display inline or inline-something, then you can set white-space:nowrap on the container. However in this case it seems (in FF anyway) there's a mysterious space between the elements, which for my purposes yesterday, would have been a problem.

Tesserex
I'm not sure this is true. There are ways to control wrapping behavior in CSS.
jlew
then someone lied to me in my question yesterday. Will delete if I can find it.
Tesserex
Maybe they're correct in some kind of limited scenario. As a general statement, I don't think it's accurate.
jlew
+6  A: 

CSS doesn't have a good way of handling data which is genuinely tabular. If your data is, itself, structured in rows and columns, then the table tag is still the best way of presenting it. While you can "fake it" in CSS, it results in complex, difficult to maintain code for no real reason.

Note that tabular data doesn't necessarily always mean just tables of numbers. Sometimes forms and other types of interactive content can be tabular as well, if their fields logically group themselves into columns and rows. The key point is to ask yourself, "would I think of my data as rows and columns if I wrote it out on a page and the computer had nothing to do with it?"

Dan Story
+1 despite "for no real reason"
ANeves
@sr pt - I disagree. The end result is what the user sees. If using an all CSS design makes you feel good inside, but takes you three times as long to do, you are accomplishing nothing other than costing your company time and money.
Nemi
Dan is correct - a good definition of 'tabular' is 'stuff that lines up neatly in rows and columns'. Like most data entry forms. Like newspaper-style columns. Like the main structure of most web sites.
Ray
I wish I could upvote this more than once....
Nemi
Note that I'm still not advocating doing, say, your main site layout using tables. CSS offers many improvements over the table model. But lots of elements internal to sites -- such as forms with multiple columns where the fields need to align column-to-column -- *are* structurally tables. It's not just a layout convenience.
Dan Story
+5  A: 

I would switch to css based layouts if I could. The sematic arguments are correct, but there are practical considerations. Tables will:

  • absolutely prevent 'float wrap' where a div will fall to the next line because there isn't enough space for it
  • give you same-height columns
  • allow dynamic layouts where widths and heights are not known until run-time
  • provide colspans and rowspans
  • reduce the number of SO questions asking how to do stuff without tables :)

There are css display properties (table-cell, etc) which mimic some of this, but I don't believe the support is widespread enough to use them yet (unless you can control your user's browser selection).

The site I work on requires competely dynamic column widths in the layouts. Multiple customers use the same site templates, and I have no idea what they will put into the menu or page header or content cells. (And no idea what they will find attractive, which is another issue...) Using a single outer table to lay out the main sections of the site allows the flexibility I need without worrying that a slightly-too-wide menu will push the main content box down to the next row, or that background colors won't fill the required height.

In a perfect (to me) world, we would have <table>s for tabular data, and another, nearly identical set of tags for layouts - call it <layout> (along with corresponding row and cell tags). Or, add a 'mode' attribute to the <table> tag - the values would be 'data' and 'layout' so that screen readers and search engines would know what to do. Maybe in html 6...

Edit: I shoud add, regarding the 'float wrap' thing - there is a current question on SO with an answer that works pretty well here. It is not perfect, and too me it is too complicated, but it would resolve the problem in many cases.

Ray
+0 for first, -1 for the 2nd and 3rd, +1 for the 4th and fifth. :D
ANeves
@sr pt: I am glad you gave me +0 for the first, instead of -0 ... Seriously, I have seen partial workarounds for most of this stuff, but never for truly dynamic widths (my 3rd). Have you got something for me?
Ray
A: 

What can tables do that CSS positioning cannot?
In theory, nothing, since you can use display: table;, display: table-cell; or other such values for display.

<ArgumentOnSemanticsUsabilityAndAcessibility />

ANeves
Well, yes. But that makes it into a table so I consider that outside the spirit of the question.
jlew
But other than `ensure [float'ed etc] elements don't spill` and `liquid col/row spans` I can't see anything they can do that you can't achieve with CSS. The only playable card in this game for most of the situations is `save time`.
ANeves
A: 

Use them(Tables) in the markup and you don't have to break your head about positioning or about cross browser compatibility. Tables work almost the same way across browsers

dkris