The Real Deal Behind Table-less Layouts.
Posted on October 28, 2008, under Web Design, Web Development.
Tables, as a part of HTML, have gotten a bum deal over the last few years. Yeah, they were the darling of web design for a long time. Strutting their stuff with the latest and greatest cutting edge sites. Going to all the fancy website parties like Amazon and CNN. She even made it to the White House. Life was beautiful. Granted, she was never made to do those fancy layout tricks the designers in the know made her do. She was, however, a real trooper and did what we asked.
Now she’s the down-and-out kid. The designers who embraced her in her youth are now turning their collective noses and embracing DIV and SPAN, leaving her out in some cheap motel with a 2 dollar bottle of whiskey, half a pack of cigarettes and distant memories. “I was supposed to hold columnar data,” she keeps muttering to herself.
Ok, here’s the reality. Tables are good, they work and they are useful for good and proper representation of data. Tables are important and deep down are good natured and you can trust her with your little puppy. Over the years, designers abused tables for many reasons: namely because most designers think in grids (especially if you’re a print designer) and tables worked well in browsers. CSS support was sketchy at best and well you could do a lot with tables.
Fast forward today and designers are doing the doing the same thing with DIVs and SPANs.
In a recent article in Digital Web Magazine titled Everything You Know About CSS is Wrong, Rachel Andrew covers the table, table-row, table-cell, etc. display support now available in IE 8 beta. As mentioned in her article you can essentially turn a series of nested tags into a table-style layout using these values for the display CSS attribute. Thus you get all the table-based layout goodness without using any table tags.
Here’s an example, consider the following markup:
<div id="wrapper">
<div class="row">
<div class="cell">Column 1 content</div>
<div class="cell">Column 2 content</div>
<div class="cell">Column 3 content</div>
</div>
<div class="row">
<div class="cell">Column 4 content</div>
<div class="cell">Column 5 content</div>
<div class="cell">Column 6 content</div>
</div>
</div>
Now, let’s style it with the following CSS:
<style type="text/css">
#wrapper { display : table; border-spacing: 5px; }
.row { display : table-row; height: 125px; }
.cell { display : table-cell; border: 1px solid black; background-color: #ffd; }
</style>
Will yield the following result:
You can see how table-like the output is. The “table cells” here are rendered the same way the browser would render for a table. All the divs with display : table-cell inherit the same height from the row. For a simple layout where you as a designer need columns to have the same height, this is a pretty cool solution.
Now, if you’re a designer whose been in the trenches for more than a couple of years, you’re looking at this and crying as you reach for the emergency bottle of Wild Turkey. You spent many agonizing months trying to switch your thinking to Web Standards based layout and learning how to lay things out the “right way.” You’re probably mourning all the cool multi-dimensional nested tables which were more complex than getting a stable nuclear fusion with 2 silver spoons, copper wire and a zippo lighter. But hey! It rendered in IE!
Ok, here’s the bottom line.
Tables are for tables, table layouts are for… well … tables! Saying otherwise is sending a dangerous mixed signal to designers to go back to the bad habits of the past. Add to that the fact that CSS Table layouts using DIVs, don’t work in IE 7 nor IE 6. Mix in the fact that there’s no CSS equivalent to ROWSPAN and COLSPAN. Sprinkle in a ton of extraneous DIVs and SPANs just to get this kinda layout working and you have a pretty vile Table Layout soup. CSS or no CSS, I don’t like the smell of this.
Give me clean, semantic markup, broad CSS support and javascript to fill in the design gaps and I’m happy.
Rachael, everything I know about practical web design is right!
2 Responses to “The Real Deal Behind Table-less Layouts.”
Leave a Reply











Hiya,
I have to say i disagree, you seem to have missed the point of what Rachel was saying.
Rachel was not suggesting to markup up tabular data using non semantic code, she was explaining how some underused (and gaining support) CSS properties can use the behavior and styling of a table like system to archive grid based designs.
You seem to have confused the purpose of markup and styling. Lets start of with a semantic blend of some nice old fashioned HTML.
Lets give ourselves (barring the strict doctype and all that jazz, lets just keep things simple here) the following to work from:
The Site Name!
This site has name, it is very wonderful. I am a brief description of the site
Title of Article
article content
Recent Posts
Recent post title
recent post title 2
The point that Rachel is making is i can take this same semantic markup and use the “table style CSS3″ attributes to style this into a 2 column layout without the need for floats and clearing etc.
In her article Rachel writes:
“The table element in HTML is a semantic structure: it describes what data is. Therefore, you should only use the table element if the data you are marking up is tabular—for example, a table of financial information. If it would normally be stored in a spreadsheet on your computer, it probably needs marking up as a table in HTML.
The table value of the display property, on the other hand, is simply an indi cation of how something should look in the browser—it has no semantic meaning. Using a table element for your layout tells a user-agent, “This data is tabular.” Using a bunch of divs that have the display property set to table and table-cell says nothing to that user-agent other than asking it to render them visually in a certain way, if it’s capable of doing so.”
This is a future technology which will enable easier and more robust layout on browsers in the future.
The issue with tables for layout is that they were discussing XHTML tables inside the content.
Rachel is discussing how a browser objects the styling of elements.
To understand her article look further than the simple examples used as an analogy to explain a further concept. In her examples she is marking up what could be tabular data (we don’t know, no data is placed) or each of the divs may just represent your standard semantic structure.
Building a table (containing tabular data) inside divs and spans IS wrong, but treating elements on a page with the styling ideals of a table as placement is not.
This will in the future make web layout more flexible, easier and simpler to produce and generally better.
hope that helps, need to rush got to go shopping!
^licks^
Jamie & Lion
@ Jaime,
Hey, thanks for the response!
Your point is well taken. I absolutely agree that, used wisely (for good, not evil) the table display type is an elegant solution to many problems we face as web designers.
The problem is that a good number of the designer/developers I know and know of, had a hard transition to CSS-based layout in the first place (heck, a few of them fall back to tables when the CSS get too complicated for them).
Add to that the missing support in the current IE, and pragmatically, using this pattern seems a little half-baked.
Personally, I’m looking forward to where we’re going with HTML 5 and CSS 3 support. That would be very cool.
Thanks!