TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup

By Dimitri Glazkov
Posted on 05/02/05

You must be really living out in the sticks if you haven't heard by now that using HTML tables for layout is bad. Markup is for content, CSS is for presentation, we learned.

You must be living in the land of magic mushrooms if you haven't realized by now that making CSS do exactly what you want is easier said than done.

See, in the ideal, happy-go-lucky world, everything is just right. The content, custom-tailored by suave professional markup writers, fits perfectly into the widths and proportions of your template. The browsers support standards at exactly the same level and in exactly the same way.

Too bad we don't live in Mayberry. With the loony Czar "The Exasperating" CSS 1.50304 ruling the presentational realm, it is surprisingly hard to build templates that are not brittle. Even The Man himself is battling with the idiosyncrasies of the dominant Web browser. And he's the sole content contributor to the site! What if the entries were written and posted by someone who neither knows nor cares about the quality of markup, which last time I checked, is the absolute majority of your typical content contributors?

The issue becomes even more complicated when the layout is fluid, because its exact sizes are not known at any given time. And when the business requirements call for more sophisticated visual concepts than your typical "two-column", "three-column", and "three-column with coke and fries", it becomes clear that the old Czar alone may not be able to hold the kingdom together.

The "Stretchy Pants" test

One of my favorite TV characters, Frank Barone of "Everybody Loves Raymond", was ecstatic to finally find a pair of slacks that fit just right his lesser than strapping figure. Nevermind that his wife Marie had secretly purchased them at a maternity store -- Frank loved his "stretchy pants", in which his beer-drinking, cannelloni-devouring gut would never feel too tight. In a very similar manner, your layout must accommodate the fact that the content may sometimes grow a bit of cellulite here and there. Therefore, in order to be deemed ready for the real world, any page layout must withstand this simple test:

In each area of the layout that will have changing content, place markup whose presentation exceeds the width and/or height that is originally allocated for the area. Doing so must not cause the areas to:

  • Rearrange and change (break) the layout
  • Bleed one over another
  • Hide content of other areas.

This condition should still hold true if the browser window is resized to any width or height.

The ones with the heightened usability sense would add that these changes must also not trigger the appearance of in-page scrollbars. Go ahead and play with the pure CSS-driven sites. Download the source code of their pages, test it. View these pages in IE, view them in Mozilla, maybe even check them out in Opera. You will see that hardly any of them pass the test. In fact, if you find one that passes it and has more than one column, let me know.

The secret that CSS gurus have been trying to hide from you

But guess what? The table-driven layouts (if designed properly) pass the "stretchy pants" test with flying colors. Perhaps nobody enunciated the issue better than Andy Budd and Dave Shea in their insurgent strike against us structural markup purists: tables are bad, but they may be necessary to keep the layout intact in real-life conditions. Olav Junker sums up the problem in his comments:

CSS is perfect for basically single-column layouts. Secondary blocks like sidebars can be placed outside the main column with float. This solves the layout requirements of many websites, but requires the designer to rethink the layout as column-based rather that grid-based. It’s not just a case of moving some attributes into a slightly different CSS syntax.

However, sometimes you really need blocks aligned in two dimensions. You can emulate it with positioning and fixed sizes, but this will not, like tables, adjust gracefully if content is changed.

So my point is, it’s not a case of CSS being harder to learn and tables beeing more familiar (the same could be said of font-tags then, but i dont think many uses them any more), its a case of CSS not supporting 2D grid-layouts.

As painful as it is to admit, the amalgamation of rendering engines that's currently available on the market simply does not provide a robust enough implementation of the 2-dimensional layout grid. You can float and slide your divs and spans all you want -- these hacks will still remain hacks, because they only provide a simulation of the layout that's aced by those darn tables.

We can rebuild him. We have the technology

So, what's the solution? How do we keep provide a 2-dimensional grid to support the layout of our markup structurally correct markup? Well, how about this: let's augment the rendering engine with the missing layout capabilities.

Huh? Are we trying to build a new browser now? Hopefully not. Just want to improve the existing ones with a slight twist of Javascript. Pull out the old trusty blade of client-side scripting to enforce the placement of your content areas in a 2-dimensional grid. Many of you 'scripters probably just saw an elaborate mesh of "onresizes" and hidden iframes to account for various size changes flash before your eyes. No, it's actually much simpler than that. Let's think for a second. Don't we already have a nice logic that does exactly what we need and is already build right into each and every one browser on this planet? Let's see, what do we call those...? Tables, was it? You betcha.

The gory details

Here's the gist of the technique: using standard DOM methods, inject a table where it is needed to support layout. Let's use this composition as an example. Now, you fancy design folk might start pooh-poohing the awful choice of colors and lack of style, but let's try to keep our focus on the topic.

First, we write the markup for the content and its structure:

  <div id="Page">
   <h1 class="Title">Your Company Name</h1>
   <ul class="Tools">
    <li>
     <a href="#">Home</a>
    </li>
    <li>
     <a href="#">Site Map</a>
    </li>
    <li>
     <a href="#">Search</a>
    </li>
    <li>
     <a href="#">Contact Us</a>
    </li>
   </ul>
   <div class="Content">
    <p>
     Lorem ipsum etc ...
    </p>
   </div>
   <ul class="Links">
    <li>
     <a href="#">Related Link</a>
    </li>
    <li>
     <a href="#">Another Related Link</a>
    </li>
    <li>
     <a href="#">Vaguely Relevant Link</a>
    </li>
    <li>
     <a href="#">Just some link</a>
    </li>
   </ul>
  </div>
 

Next, we inject our tables:

  var page = document.getElementById("Page");
  var pageItems = new ClassNameBag(page);
  var pageTable = new LayoutTable(2, 2);
  pageTable.appendChild(1, 1, pageItems.Title);
  pageTable.appendChild(2, 1, pageItems.Tools);
  pageTable.appendChild(1, 2, pageItems.Content);
  pageTable.appendChild(2, 2, pageItems.Links);
  page.appendChild(pageTable.node);
 

And finally, we use CSS to complete the composition. Looks simple enough? Let's examine the injection code line by line. Line 1 should be pretty self-explanatory: the element by id of "Page" is retrieved. Basically, we grab the root of the DOM tree that represents mentioned above markup.

Line 2 is just creating a ClassNameBag instance, which doesn't relate to the technique directly, but is useful, because it creates an object with properties, each containing the child of the element, supplied as a constructor argument, and named after the child's class name. Now, for instance, I can access <ul class="Links"> element simply as pageItems.Links.

On Line 3, the actual injection magic begins: a new object named LayoutTable is instantiated. The LayoutTable encapsulates the "to-be-injected" table and its constructor has the following signature: LayoutTable(columnCount, rowCount [, className]), where columnCount and rowCount specify how many columns and rows, correpondingly the table will contain, and the optional className parameter allows to add an extra class name qualifier to table's "class" attribute (which already has "Layout" class name assigned by default).

The LayoutTable provides nprovides a single method appendChild(column, row, node), which is similar to your typical element.appendChild method, except it appends the element, supplied in the node argument in the specified row and column of the table. Lines 4-7 distribute the contents of the Page element to their corresponding locations in the 2D grid (a.k.a. layout table).

And finally, on Line 8 we attach the layout table back to the Page element. The LayoutTable has one property node, which contains the actual DOM node of the table that was built with the code above. At this point, the injection is complete, and the table becomes part of the DOM.

In order to allow for more styling flexibility, each table row is given className of "ry", where y is the number of the row ("r1" and "r2" in our example), and table each cell is assigned className of "cx", where x is the number of the column ("c1" and "c2" for our table). This simple naming trick lets us control the presentation of rows, columns, or even individual cells in the layout table. For instance, "table.Layout tr.r1" will select the whole row 1, "table.Layout td.c2" will select the column 1, and "table.Layout tr.r1 td.c2" selects just the second cell of the first row.

Suddenly, CSS and tables are friends again. The old nemesis of structural markup comes back to the good guys' side and saves the day. The barriers are broken, problems are solved, the happy end ensues, and tears of delight flow down the cheeks of sentimental readers.

What's your name, stranger?

Now hang on just a second. Obviously, we have a technique here. And as far as I can tell, nobody had named it yet. Maybe I should try my hand at the Four-Letter Moniker Wheel of Fortune. Let's see here... It's a Table Injection Technique! Well, that's only three letters and a couple of notches past PG-13. How about this: BOTOX, a quick way to smooth over nasty old wrinkles by injecting normally toxic stuff into the facial area of your page. Clever, but nah... I can just smell the lawyers circling around my head with this one.

Wait, wait.. I think I got it. The Table Injection for Layout Technique, or TILT! Woo wee! I think I just got me my own 4-letter abbreviation! Yup, TILT it is. Are you ready to TILT it?

Surgeon general's warning

Just like anything that sounds too good to be true, TILT comes at a certain price.

  • Using client-side scripting to add extra layout functionality to your browser's rendering engine requires, uhm, client-side scripting, which may or may not be available on the browser of your visitor.
  • TILT modifies the DOM tree of the page, which is something that has to be accounted for if you are doing DOM work for other purposes.
  • Using tables for layout while keeping the markup clean is addictive and may lead to inexplicable waves of feeling joy and urge to hug and kiss co-workers and even total strangers.

Ok, maybe not the last one. However, when all said and done, this technique definitely deserves a good look. It has potential of making your hacking with CSS columns and floats obsolete and clearing up the way for you to actually starting to enjoy your markup.

Comments

  1. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dean Edwards on 05/02/05
    This is totally brilliant!
  2. Re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by haacked@gmail.com (Haacked) on 05/03/05
    Brilliant! Glad to see you finally blog this!
  3. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dan Mall on 05/03/05
    Wow, and just like that, it seems that tables are back again. I'm not sure how to feel about that, but I definitely respect and appreciate your skills and this post.
  4. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Shaun Inman on 05/03/05
    I think as with any clever idea the potential for abuse is high but it still remains a clever idea. The only thing that concerns me is that in a production environment you'd have twice the overhead if you plan on being respectful of your JavaScript-less viewers; having to write CSS for the page with inserted tables and without.

    I'd be interested in seeing an implementation of this where the layout table was used as a fallback only if the browser was loose with floats (I'm looking in Redmond's direction--on both platforms).

    Of course, can you really call it a fallback if almost 90% of your viewers fit that demographic?
  5. Modifying the DOM like this is a bad thing
    Posted by Anne on 05/03/05
    Note that you are modifying the DOM and since browsers and devices use the DOM for styling, retrieving content and semantics you mess up stuff. Not for Google obviously, but how about some theoretical accessibility viewer that runs on Firefox?

    (sIFR modifies the DOM tree too, but does so in a way that doesn't really interfere with devices as all elements and attributes that are added have no semantics whatsoever.)
  6. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Haacked on 05/03/05
    If a user doesn't enable javascript, they get a nice unordered list (ul). What's not to like? ;)

    Besides, unless they've explicitely turn off Javascript, Javascript-less browser implies CSS-less browser as well.

    This technique may not degrade beautifully, but it does degrade gracefully in that the content's still there.
  7. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by MT on 05/03/05
    I like the idea, and I agree with the premise. It's not a fix for our woes -- but our only hope of that is a browser with real CSS support becoming dominant. And while it sucks that we all have to waste our time rephrasing ourselves endlessly for the benefit of Explorer, this seems like a fairly painless way of doing exactly that.

    To answer Shaun, hell yeah. Unless you want to call it a fall-forward, which IE more or less does as well.
  8. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Danila Medvedev on 05/04/05
    Have you checked this very page in Opera? In Opera 8 if the window width is small enough, the text drops below the left sidebar!
  9. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Eric Guerin on 05/04/05
    This agian proves how bad CSS can be for complex page layouts, I like this technique and is a cool idea, but I would much rather have a CSS/XHTML markup that doesn't require JavaScript or CSS hacks to make it work accross browsers, I would like a Pure CSS Layout format, which doesn't require making hundreds of additional DIV tags in the layout to make things work as expected.

    CSS has a long way to go, Table are just far superior for layout.
  10. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Olav Junker Kj&#230;r on 05/04/05
    Hey, you should implement this as a behavior, so it could be attached through css!

    @Eric Guerin: Actually CSS supports table-like layout through the display:table-* types. Its just not supported by IE.
  11. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/04/05
    Danila,

    Actually, this page breaks very consistently in all browsers :) Have you looked at my contact form in Firefox?

    I appreciate the comment, though and agree with your implicit suggestion that before writing about good layouts, fancy tests and techniques, I should've fixed my own crap first.

    And I will, I promise. Just as soon as I get to it! :)
  12. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by mithrandi on 05/04/05
    For browsers that support it, I believe you could merely style the elements with the display: table-* display styles and achieve a similar effect, without Javascript.
  13. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/04/05
    Anne,

    First off, thanks for stopping by. I am a fan and read your blog religiously. You're my standards guy :)

    I agree (both here and in the text of the post) that DOM modification is a negative side-effect of the technique. It's not something that should be ignored or taken lightly.

    However, from my point of view, all this really comes down to the balance of theory and practice. In theory, I want neither to use tables in my markup, nor to do any of this DOM hacking. In reality, I may have to choose the lesser evil.
  14. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Tom on 05/04/05
    Powered by ASP. baaah...

    Anyways, you're still using tables. Above that, the page is totally dependant on a bunch of javascripting, which means a page could render slowly even after the page has been downloaded.

    So why exactly does everyone hate tables so much? They seem to work fine for me, always. All browsers support them, and they don't need any hacks. CSS includes plenty of table-moding attributes, so what's the big deal? CSS was originally created to override browser defaults... So what's next? Pure CSS pages, where the only HTML tags allowed is STYLE and SCRIPT? Slash that, style's can be added within the script.
  15. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by fohara[spam block]@mac.com on 05/05/05
    You must be reading my mind! I've spent the lat week or so feeling very, very bad about tables in my layout!
  16. re: tables etc.
    Posted by spangle on 05/05/05
    There is no 'best' way to design a website, no one right way to incorporate standards into your workflow. Many transitional approaches may well be better suited to particular sites and tasks. Table and frame-based layouts may appear to be the right tool for the job, however I'd argue this is in fewer and fewer case now.

    However, standards have been defined for a reason. Not to inflate the egos of a few techies, or for people to force one so-called 'superior' technology on others. They are there so that we can make sites that *everyone* can read and access. Whether using a screen reader, accessibility options (high-contrast, larger fonts etc) or simply a non-standard browser.

    Separating style from content seems very sensible, no matter how you choose to do it. Its about forwards compatibility. Think about it, you want a redesign in a year's time? No problem, just change the styling and lo-and-behold it looks like a whole new site. This would be much harder and more labour-intensive with semantically-styled (table/font tags) sites. Applied to large sites, of 500+ pages say, it saves a huge amount of time and money.

    It is, of course, your site and your choice.
  17. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/05/05
    spangle,

    Thank you for communicating this important point! I almost put something like this in the article, but it already ran too long. Yes, ultimately this technique is precisely what you're talking about: separating style from content.

    Having tables generated with client-side DOM rather than on the server has one tremendous advantage -- your markup leaves the server semantically valid.

    And when the browser support is good enough to build layouts without injecting tables, you won't need to sift through the server code and rework your rendering logic to remove the table tags.
  18. Stop me if I missed something...
    Posted by Gregory Wild-Smith on 05/05/05
    Ok.. so you are using JS to add tables. Why?

    I honestly can't see the point in using JS to do what you could do in the code. This seems like a slower, cludgier, way of adding tables than just typing them in the code.

    Its clever, but "leaving the server semantically valid" doesn't matter if you are just going to garble it client side.

    I agree that the current implmentation of CSS in browsers isn't good, but I really don't see the point of this hack, and it is a hack. If you have use a hack like this to get something working I'd say that you're constructing the page wrong in the first place...
  19. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/05/05
    Gregory,

    You're right, it is a hack. It's not mentioned anywhere in the article, but it is a sure bet that having to inject anything in DOM in order to support the layout is going to be a hack.

    As for the rest of your comment... Well, think about it this way: this is a way to get by until "display:table" support property implemented across all modern browsers. Because it is dynamically bound, it keeps the markup clean, and allows, with minimal modification, to switch to using display:table family when it's ready for primetime.

    But if you don't mind using tables for layout in your markup, I don't see why you would be interested in using this technique.
  20. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Bob Campbell on 05/05/05
    Amen brother!
  21. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Tom on 05/05/05
    This seems to be a bit overly complex. I think people should just choose tables or css to control layout. With tilt you are throwing a javscript hack into the mix.
  22. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Alejandro Perez on 05/05/05
    I know the CSS purists will see this as an awful hack. But I think TILT has great potential. Out of the bat, I think it isn't as hackish as other solutions since it doesn't need to be adapted for most browsers (compared to CSS hack that is impossible to know why you put the hack without knowing the browsers) and it's more powerful than tables since you can change the layout pretty quickly and easily. TILT is great for having different sites in the same server allowing different layout and styles for the same pages drawn consistently. Most of the opposition I hear applies also to AJAX and nobody can say that it has worked great for google.
  23. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by David on 05/05/05
    Surely, you can't be serious. If you need a table that badly, just <em>use</em> a table.
  24. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Tom Trenka on 05/05/05
    Hmm. Seems to me that what you really want here is XSL, which--good lord--already exists! My oh my!

    Seriously though. If you're so concerned about making sure something that is semantically correct goes to the client first, and then tapping into the power of the client "to make it right", there are other techniques (like the aforementioned XSL) that would suit your purposes better. In fact, you could get all "super-semantic" and give actual MEANING to the hierarchical data you are sending to the client, and then use XSL to make it work properly.

    Did I mention XSL?
  25. In response to comment by: Tom Trenka
    Posted by Dimitri Glazkov on 05/05/05

    XML/XSLT-based rendering (which is I think what you meant by "XSL") is not widely supported today's browsers (IE6 and Gecko-based only), and it offers very limited fallback capabilities.

    If you wish to build real-world, public production Web sites with XML/XSLT, I would strongly suggest to reconsider.
  26. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Eugene T.S. Wong on 05/05/05
    Hi. Thanks for sharing TILT with us. I really appreciate the work that you put into this. I'm so glad that stuck with it and finished reading the blog entry.

    I totally agree with you in that it keeps the markup and css pure.

    To be honest, most of the people who use your site that need the JavaScript are probably IE users. Maybe you should only let them download the script? Most modern browsers seem to do alright with {display:table-foobar}. Also, you don't really want handhelds to be downloading your JavaScript, right? The idea is that if you keep it localized to only IE, then you'll only be letting them suffer if something goes wrong when there are additional modifications to the DOM.

    Here's the code that I recommend you put into each HTML file.

    ---begin code---
    <!--[if IE] >
    <link rel="stylesheet" href="IE.css" media="screen" />
    <script type="text/javascript" src="tilt-ie.js">
    <![endif]-->
    ---end code---

    If you try this, I'd be interested in hearing your thoughts.
  27. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Danny on 05/05/05
    The "What if screen readers run your javascript" question can be solved quite easily. You can use a different stylesheet for aural browsers and visual browsers, and then use some javascript to check which one is being applied.
  28. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jason Diamond on 05/06/05
    This is cool.

    One issue: Would IdNameBag be more appropriate than ClassNameBag? Class attributes can contain multiple values. A parent element can also have multiple child elements with identical classes. These things can't happen with id attributes (or aren't supposed to).
  29. IdNameBag idea
    Posted by Dimitri Glazkov on 05/06/05
    Jason,

    Yes, I think IdNameBag would work fine, too. The ClassNameBag is just a utility class, which I used to to make the code easier to read.

    Only the LayoutTable is needed for the technique to work. You can retrieve the nodes using just DOM methods.
  30. Nice Trollpost
    Posted by &lt;&#176;)))o&gt;&lt; on 05/06/05
    Very interesting inferiour and outdated techniques are defended against advancement.

    Nice Trollpost, though
  31. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/06/05
    Eugene,

    You are thinking the same way I am thinking :) I am currently playing with an idea of creating an IE-only implementation of TILT, which emulates CSS tables.

    That way, others could just use display:table*, and IE would get "the injection".

    It's not an trivial task, however -- now you have to account for the fact that your DOM tree is different for various browsers.
  32. re: Nice Trollpost
    Posted by Dimitri Glazkov on 05/06/05
    I tried to write a meaningful response, but your comment is so circular and recursive that there's really nothing else left to respond to. You must be a LISP programmer.
  33. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by GianCarlo Mingati on 05/06/05
    in the near future maybe css will simulate accordingly a two dimensional environment.
    anyway... you rock ;-)
    GC, Rome
  34. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by David Robarts on 05/06/05
    Wouldn't it be better to use JS to read the display: table-* declarations from the CSS and then modify the DOM with tables in browser that don't support display: table-*? In other words just use JS to augment the rendering capabilities of browsers that don't support the CSS you want to use. Admittedly the JS would be more difficult to write, but it would leave all the layout information in the CSS making it easier to maintain.
  35. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/06/05
    Robert,

    Yes, it most definitely would be better -- and quite a bit more complex to implement. At this point, it's one of the directions that I am considering as the next step in improving the technique.
  36. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by patrick h. lauke on 05/06/05
    "The "What if screen readers run your javascript" question can be solved quite easily. You can use a different stylesheet for aural browsers and visual browsers, and then use some javascript to check which one is being applied."

    danny, that would be true if screenreaders actually cared about aural stylesheets (yet another situation where, in the real world, software has little regard for standards). and i'd be interested to see the js technique to determine the current "media" applied...
  37. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Danny on 05/07/05
    " and i'd be interested to see the js technique to determine the current "media" applied... "

    Well, you can look for an aural only property. For instance, "volume" is an aural only property so if your css has something like :

    #stylesheettype {
    volume: 100%;
    }

    then it has to be an aural stylesheet. Firefox doesn't accept the "volume" property for visual stylesheets - but IE does, so testing for it's presence is not enough. Your visual stylesheet should have it as well, with a value of "0". You can then test for the element's presence/value, and deduce the stylesheet used :

    var elem = document.getElementById("stylesheettype");
    if (elem.currentStyle) { // For IE
    if (parseInt(elem.currentStyle['volume']) > 0) {
    document.write("Aural stylesheet");
    } else {
    document.write("Visual stylesheet");
    }
    } else if (window.getComputedStyle) { // Via DOM
    var compStyle = window.getComputedStyle(elem, "");
    var volume = compStyle.getPropertyValue("volume");
    if (volume && parseInt(volume) > 0) {
    document.write("Aural stylesheet");
    } else {
    document.write("Visual stylesheet");
    }
    } else {
    // Not supported
    document.write("Cannot get computed style !");
    }
  38. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by flo on 05/07/05
    whee, this looks _VERY_ promising indeed - i'll sit down tomorrow and test this through with an existing three-column-css-layout with many floats'n'stuff which ofcourse until now totally fails to render in IE.

    thanks dimitri for a brilliant idea and for all the work you had letting us others know and understand (…and the most entertaining write-up of a css-technique ever - at least in my opinion ;))

    KUDOS
  39. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Ruturaj K. Vartak on 05/08/05
    Ya..
    Good one, totaly agree with you..
    I tried CSS stuff a lot many times but everytime I come across IE / Moz fighting eachother and I run back towards the safe tables :D
  40. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by patrick h. lauke on 05/10/05
    "Well, you can look for an aural only property..."

    but again, this does not work around the fundamental issue that screenreaders do not care about aural stylesheets, and that a system running with a screenreader does not automatically revert to an aural stylesheet in the browser. the user would have to explicitly select that stylesheet via a stylesheet switcher or similar...
  41. re: IE7.js
    Posted by Eugene T.S. Wong on 05/11/05
    Hi Dimitri.

    Regarding this code...

    <!--[if IE] >
    <link rel="stylesheet" href="IE.css" media="screen" />
    <script type="text/javascript" src="tilt-ie.js">
    <![endif]-->

    ...I went and looked up IE7.css. It turns out that that's what people have been doing already.

    http://dean.edwards.name/IE7/

    Maybe some of it will do what TILT wants to do. I'm pretty sure that it doesn't actually convert it to a table, but it probably takes care of the other little things. From what I've seen of the documentation, it doesn't handle display:table-*

    However, for simple tables, such as 3 column layouts, I'm sure that it won't be too hard to work with. Famous last words, huh? ;^) The reason that I believe that it won't be too hard, is because most people only 2 or 3 columns, and they will be the people creating the css. Therefore, the people who don't see the 2 or 3 columns will be far and few inbetween. Plus they should still have good access to the web site anyways. Plus the makers of ie7.js will try to create a bookmarklet [or favlet, as they are called] for users as well.

    Also, I found out from their docs that we only need something like this...
    <!--[if IE] >
    <script type="text/javascript" src="tilt-ie.js">
    <![endif]-->
    ...in other words, the script can take care of inserting the stylesheets, and thus we'll keep our code cleaner.

    I've been working on some bookmarklets that work the DOM, so if I come up with anything, then I'll let you know.
  42. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by ML on 05/11/05
    Why not just use <table></table>?
  43. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by ????? on 05/13/05
    Zdravstvuite, Dmitrii.
    Angliiskii et konechno horosho, no hochetsya chego-nibud' russkogo. Esli vam ne slozhno vylozhite, pozhaluista, russkoyazychnyi variant stat'i. Tema ochen' interesnaya, no vot English hromaet.
  44. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jonathan Puckey on 05/15/05
    I think I just overdosed on table injection:http://www.jonathanpuckey.com/undefined.html
  45. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by YouS on 05/17/05
    hi mens & girls :)
  46. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by mjk on 05/17/05
    *Conceptually speaking**

    basically, your HTML is like = XML

    and your javascript is like = XSL(T)

    cool, that its on the client side. I gotta ask though - seriously - if you put this through some "real life" paces -- would this stand up?

    Probably not. And furthermore, I'll start trusting CSS layouts for production-strength websites in, oh, let's say 2008.

    Thanks for playing! Game over
  47. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/18/05
    Vadim,

    K sozhaleniyu, poka chto ya eshe ne perevel yetu statiyu na Russikiy. No nadeyus', chto naidu vremya v budushem.
  48. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/18/05
    Eugene,

    Yes, I am pretty familiar with the IE7 project. At this time, it does not support the table-* attributes.

    However, Dean Edwards and I have discussed briefly a possibility of such implementation.
  49. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/18/05
    mjk,

    I am going to try to assume that you are not a troll for a minute. What "real life" paces are you talking about? An example would be helpful.

    As a sidenote, it is most regrettable that you don't use CSS to control presentation on your site. You are definitely missing out on a great deal of capabilities.
  50. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Eric Meyer on 05/30/05
    Interesting approach, Dimitri. I'm always interested to see people use DOM scripting to address their particular needs. It's also nice to see that the end result of your script is a very lightweight table with CSS to style its contents. The major objection to tables is not that they're tables, but that table-driven sites tend to be bloated and difficult to maintain. Your markup is anything but that.

    As someone who's often referred to as a "CSS guru", though, I do have to quibble with one thing. You said: "The secret that CSS gurus have been trying to hide from you" -- so I take it you mean like I did in the following posts:

    http://meyerweb.com/eric/thoughts/2004/09/03/sliding-faux-columns/
    http://meyerweb.com/eric/thoughts/2004/09/05/css-grids/
    http://www.meyerweb.com/eric/thoughts/2004/09/06/to-be-tabled/

    Good thing I was trying to hide that information from the world. Just imagine what it would have been like if I'd been trying to talk about it in public!
  51. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 05/31/05
    Eric,

    Thank you for visiting my site. It's an honor. Yes, I may have gotten a wee bit too sensational with my headings. I sincerely didn't mean to offend you.

    I guess I probably should've said "CSS pundits" to emphasize the jest of the sentence. What I meant to communicate is my reaction to rash "tables are obsolete" exclamations that are based on little experience and reading one or two articles on the Web.
  52. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Aleksandr Ne Pushkin on 06/01/05
    Hello!
    I think we don't need to use DOM.
    This page is good looking in Mozilla Firefox, Opera and IE. It is also good looking in old browsers without CSS. Banners are under menu and content.
    (RUS: Ya ne tak horosho govorju po angliski, prostite esli chto ne tak. Hotel skazati chto stranitsa rastyagivaetsya, to est' rezinovaya, no ne znaju kak po angliski rezinovaya. 8)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html>
    <head>
    <title>= TITLE =</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
    <link href="screen.css" rel="stylesheet" type="text/css" media="screen" />
    <!--
    The screen.css file code:
    #header {
    background-color: #FFF8DC;
    }
    #col-left {
    position: relative;
    z-index: 99;
    float: left;
    width: 160px; /* = left column width */
    background-color: #D2FF91;
    }
    #col-center { /* <-- only one block-helper */
    position: relative;
    float: left;
    width: 100%;
    margin-left: -160px; /* = -( left column width ) */
    margin-right: -380px; /* = -( left column width + rigth column width )*/
    }
    #main {
    margin-left: 160px; /* = left column width */
    margin-right: 220px; /* = rigth column width */
    background-color: #E6E6FA;
    }
    #col-rigth {
    position: relative;
    float: right;
    width: 220px; /* = rigth column width */
    background-color: #FFFFB2;
    }
    #footer {
    clear: both;
    background-color: #FFE5E9;
    }
    -->
    </head>
    <body>

    <div id="header">= HEADER =</div>

    <div id="col-left">
    ID col-left (Menu)<br />
    <ul>
    <li>First Item</li>
    <li>Second Item</li>
    </ul>
    </div>

    <div id="col-center">
    <div id="main">
    ID main (Content)<br />
    Go ahead and play with the pure CSS-driven sites. Download the source code of their pages, test it. View these pages in IE, view them in Mozilla, maybe even check them out in Opera. You will see that hardly any of them pass the test. In fact, if you find one that passes it and has more than one column, let me know. </div>
    </div>

    <div id="col-rigth">
    ID col-rigth (Banners)<br />
    In fact, if you find one that passes it and has more than one column, let me know.
    </div>

    <div id="footer">= FOOTER =</div>

    </body>
    </html>
  53. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 06/01/05
    Aleksandr,

    "Rezinovost'" (Fluid) -- yeto odno delo. "Rastyagivaemost'" (Stretchy) -- drugoe. Rastyagivaemost' predpolagaet, chto dannye v kolonkah mogut prevyshat' predopredelennuyu shirinu i pri yetom vse ravno sohranyat' layout. Vot, vstav' takoi cod v tvoyu stranicu:

    <div id="col-left">
    ID col-left (Menu)<br />
    <ul>
    <li>First Item</li>
    <li>Second Item</li>
    <li>A_very_very_long_string_that_has_no_spaces_in_it</li>
    </ul>
    </div>

    I ty uvidish' o chem ya govoril v stat'e.

  54. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Aleksandr Ne Pushkin on 06/01/05
    Dimitri,

    Ponimaju...
    problema est', eto udar po beztablichnoi verstke
    Spasibo... vsego horoshego...
  55. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jimmy on 06/30/05
    This is the dumbest idea I've ever heard of. Semantic markup serves a very valid purpose, and your hack eliminates that service.

    Tables were never meant to be used for layout, regardless of how they get there. With styles disabled, your page will still be "styled" with your tables. This is incorrect as it draws back the benefits of CSS: portability and seperation of style and content. You cant switch css templates without changing your markup, because your markup is incorrect!


    I would suggest that you go out and learn how to use CSS properly before you put out tips like these. There are too many people *begging* for a lazy way out, and you're giving them one under false pretenses.

    Bad design taught by a bad designer. Ugh.
  56. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 06/30/05
    Alright, Jimmy, I think if you call me names, it's only fair for me to ask you to back it up with something.

    Why don't you post here the markup and the stylesheet for the page in my example that looks and behaves the same way as my example, does not use tables, and still passes the "stretchy pants" test?

    Otherwise, you're just another pathetic troll who doesn't know what the hell he's talking about.
  57. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jimmy on 06/30/05
    http://www.mentallyretired.com/tilt.html

    If you disable styles completely you'll notice my page still has nice semantic markup, which is important for screenreaders and people on devices that cant use your javascript, like cellphones. Any questions?

    Also, I never called you names, I just said you're a bad designer. Designer in training maybe. Either way, stop teaching people bad habits.


    Jimmy
  58. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/01/05
    Jimmy,

    Ok, I take back the "pathetic troll" tirade. However, your markup, while it emulates the 2-dimensional grid, has one major problem: it is not "stretchy".

    For a small demo, increase the length of the words in title (how about "Interplanetary Society of People Who Still Think That Two-Dimensonal Grids are Not Needed In Web Layout"). They will start going "under" the top navigation sidebar pretty soon.

    That's the problem with emulation of a 2-D grid: you can make it "almost" work, but not completely.

    Have you read my artile or just skimmed through it? It seems that you're still not convinced that CSS isn't capable (as it is supported now) to provide robust grid layouts. Maybe I should point you to Dave Shea's and Eric Meyer's articles about that? But I already did. Heck, Eric did it himself earlier in comments!

    Oh, and I never claimed to be a designer. Not a good one, not even one in training. The world doesn't revolve around designers, you know.
  59. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jimmy on 07/01/05
    Fair enough. I can fix that.

    However, you cant change your layout with just stylesheets.... For visitors on portable devices and wtih screenreaders, your page is a nightmare.

    I'll post again later when I have a few minutes. Day job and what not.


    Jimmy
  60. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/01/05
    Jimmy, as I already stated before, this all really comes down to not whether tables are semantically valid to use for layout (which they are not), but whether you have to fall all the way to hard-coding tables into your markup or still salvage some semantic grace by using JS.

    I can't wait for your next iteration. It will be very educational for me if you indeed make your example "stretchy" in all content areas. I, along with many others, don't know of a way to do that without resoring to tables.

    Also, do take a look at my example page in a portable device. You might be pleasantly surprised.
  61. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Philip on 07/01/05
    I have to agree somewhat with Jimmy, but not entirely. I am not opposed to using tables, but I am opposed to the failure to use proper structure just for the sake of style.

    The web is so useful because it is "platform" independent. Unfortunately many designers fail to code for platform independence by designing using improper structure. Tables used for styling is improper structure. Different tag elements exist because a website should look like an outline when structure properly. Headers should use H(x) tags while paragraphs should use P tags. Lists use OL and UL while definitions use DL. The same is true of the TABLE tag. It is for tabular data, so use it that way only.

    On the flip side, I love using CSS and JavaScript together. But CSS is for style as JavaScript is for behavior. Everything has it's proper place and usage. Tables are for tabular data, and thus should be used for their intended purpose. CSS was developed because style was lacking from HTML. Now HTML is truly markup again with style being handle by CSS.

    If you take some time to learn the reason for each element in web design then you will understand the capabilities and limitations of each element. I am sure you find that many of the limitations you think an element (CSS,HTML,JavaScript,etc.) has can be overcome without employing any other element. It just takes some adjustments in our thinking.

    Also, what happens when the user doesn't have JavaScript enabled? Poor thing doesn't get to see the beauty of your site.

    This proof of concept is great. Just don't use it in real life design.
  62. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/01/05
    Philip,

    All you said is true and correct -- in theory. Unfortunately, it is also just semantic purist demagoguery, when not backed with real-life capabilities. As I stated in my article, just CSS is not enough. That's why you need JS to help with presentation.

    If you feel that there is something that you could contribute to solve the simple exercise that I've outlined for Jimmy, please feel free to post it here.

    Otherwise, spare us the rhetoric.

    And, to address the question of JS disabled, have you heard of "progressive enhancement" and "graceful degradation"? It's all as applicable here as it is in any other scenario.
  63. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jimmy on 07/01/05
    http://www.mentallyretired.com/tilt

    I also added a few new stylesheets to completely change the style. The newspaper one doesn't pass the "Stretchy test", but I just put that style in there to show the versatility. The markup on all the pages is exactly the same, save for the link to the CSS file.

    The default style passes your stretchy test. It obviously took me an extra hour or two, but I can easily update the look of the page with CSS, including rearranging the layout, as witnessed by the newspaper css.
  64. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/01/05
    Impressive work, Jimmy. I applaud your efforts and obviously you know a thing or two about CSS.

    However, your layout still does not pass the test. Just try putting an image into the main body area with the width of oh, say 800px. Let's pretend it's a diagram of some sort.

    Now observe how part of the diagram disappears under the right sidebar, when the browser window width is less than around 1100px.

    I took a liberty of modifying your markup (not stylesheet) here:

    http://glazkov.com/Resources/Code/Tilt2/index.html
  65. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/02/05
    Oh, and speaking of dynamically applying stylesheets, take a look at this:

    http://glazkov.com/Resources/Code/Tilt3/Example.html

    It's rough, but should give you an idea of what's possible.
  66. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Jimmy on 07/02/05
    An 800px width image, huh?

    Simple solution for that one: Don't use 800px width images in your websites...

    You very obviously do not grasp the reasoning behind stylesheets, so I'm gonna walk away from this one and agree to disagree.

    Once you learn CSS, you design *for* CSS. You don't design for table based layouts and adapt CSS to fit them. CSS is designed to be fluid, and it is. Columns are *supposed* to go one on top of the other if your screen res doesnt support the page width.

    Have a good one!


  67. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/02/05
    Jimmy, thanks for your thoughts. This has been a good discussion.

    Your "don't use 800px width images" argument is fine for smaller, personal sites, maintained by one or two people. However, you can't really tell this to a customer with hundreds of content contributors, most of whom don't even know what CSS means.

    The "design for CSS" mentality is attractive, but it does not work. You don't design for a presentational vehicle. You design for *users*. And if you have to tell your users "I am sorry, your content doesn't fit my design", you need to review your priorities.

    All of this is beside the main point of our exercise: pure CSS layouts can't provide a robust implementation of a 2-D grid.
  68. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Chris Holland on 07/05/05
    Yo Dmitri! Great article! :)

    I'd been mulling over setting-up something like TILT for a while, but never got around to find some time for it, and I'm not sure I would've articulated it as effectively as you did. Very cool :)

    Your solution doesn't have to be a panacea for building layouts, as there'll always be developers whose business requirements allow them to code for more ideal situations, but I find it a great technique for those of us who deal with slightly uglier realities. It's just one more tool in our collective shed.

    If I can send clean, semantic markup to the client, I feel I win. If i can't super-conveniently switch some CSS on the fly because the DOM structure may be different, that's definitely something I'll happily put-up with. If the markup is already semantic, all devices will be able to present it in a graceful manner to end-users.

    all this to say, rock-on :D
  69. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Dimitri Glazkov on 07/05/05
    Thanks Chris!

    As you can see from the comments, I've also managed to upset everybody: the gurus, the DOM purists, the radicals, and even the conservatives from the tables'n'spacers era.

    But hey, maybe that's a sign of a good article? ;)
  70. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Chris Holland on 07/05/05
    i'll take infuriation over indifference any day :D
  71. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by shoshan on 08/08/05
    totally agree...
  72. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Charles Mac Lane on 08/23/05
    Great ! I will try it ASAP.
  73. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by John Gibson on 08/31/05
    Great tutorial on CSS and table injections which. It's very pleasant for webdesign.
  74. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by James Patters on 09/05/05
    I've tested the table injection and that takes much less time to realise a new internet site. Thanks for this tutorial.
  75. re: TILT: How to Stop Feeling Bad About Using Tables for Layout and Start Enjoying Your Markup
    Posted by Buba on 09/12/05
    Wow, really interesting material!
  76. order viagra
    Posted by on 10/07/07

    Compare order viagra prescription drug prices
    <a href="http://charter.net/google/index.php?_LT=GOLP_GBARGLBIN_UGLSR&q=site:pills-supplier.com&order-viagra-online">order viagra</a>
    http://charter.net/google/index.php?_LT=GOLP_GBARGLBIN_UGLSR&q=site:pills-supplier.com&order-viagra-online
    [url=http://charter.net/google/index.php?_LT=GOLP_GBARGLBIN_UGLSR&q=site:pills-supplier.com&order-viagra-online]order viagra[/url]
    <a href="http://suche.gmx.net/search/web/?su=site:pilltrade.com&generic-cialis-cheap">generic cialis</a>
    http://suche.gmx.net/search/web/?su=site:pilltrade.com&generic-cialis-cheap
    [url=http://suche.gmx.net/search/web/?su=site:pilltrade.com&generic-cialis-cheap]generic cialis[/url]
    <a href="http://search.alice.it/search/cgi/search.cgi?qs=site:pilltrade.com&buy-levitra-cheap">buy levitra</a>
    http://search.alice.it/search/cgi/search.cgi?qs=site:pilltrade.com&buy-levitra-cheap
    [url=http://search.alice.it/search/cgi/search.cgi?qs=site:pilltrade.com&buy-levitra-cheap]buy levitra[/url]

  77. buy viagra
    Posted by on 11/16/07
  78. buy viagra online
    Posted by on 11/18/07