Members
..:: Login

Features
..:: Articles
..:: Wallpapers
..:: Linux Tutorial
..:: Mobile
..:: Motorola A1200 Hacks
Tables vs CSS Challenge - Round 1
by djlosch
I am one of the many coders who subscribe to the idea that web applications are best made through a nice balance of CSS and Tables. Whenever I hear someone touting a tableless CSS design, I cringe. This is the first in a many part series to prove that tableless CSS is simply fanboyish zealotry, if not completely moronic.

..:: The Challenge

One of the CSS rules says that you're not supposed to use tables for anything except displaying data (statistics, charts, etc). In this challenge, you're required to make CSS layout that is synonymous with the following code:
1. <table>
2. 	<tr>
3. 		<td width=70%>Cell 1</td>
4. 		<td>Cell 2</td>
5. 	</tr>
6.	<tr>
7.		<td colspan=2>Cell 3</td>
8. 	</tr> 
9. </table>
This is for a series of repeating preference options in a form (lines 2-8 will repeat in a for-loop). Cell 1 has the option name. Cell 2 has the option modifier (select box, radios, checkbox, etc). Cell 3 has a description of what the option does.

..:: Constraints

With any sort of code, there are constraints.
  1. The example is written in html tables. If you cannot vizualize this layout in your head, do not reply. This is the first hurdle of competency.
  2. You must either completely forgo the float property OR you may use float, if you verify that it works with a scriptaculous slider object in Cell 2. Apparently a lot of AJAX is drawn like scriptaculous sliders, so a lot of AJAXy objects break with the float property.
  3. Your code must work perceptually on multiple browsers, particularly IE5-7, safari, opera, and FF1-3. No browser specific code is permitted.
  4. Do not include any unnecessary code (margins, padding, fonts, borders) unless it is specifically required for the problem.
  5. Your code must be 100% semantic. That is, the markup for Cell 1 must come before the markup for Cell 2, which must come before the markup for Cell 3. You also are not allowed to use [un]ordered lists. Form elements are not lists.
  6. The line down the middle of the grid (odd rows only) should be at 70% of the max object width for all objects. Thus, cell 2 should line up all the way down the page, regardless of the actual contents of cell 1.

..:: Bonus Points

You get bonus points if you can meet the following:
  1. Making the code work perceptually right is a requirement, but making the code CSS compliant is for bonus points. Pick your level of compliance. I don't care, but all of the code (CSS and html markup) must validate with W3C in some shape or form.
  2. A bunch of CSS nuts argue that bandwidth is a big issue. Since bandwidth really depends on your character set, we'll just go by characters. The table implementation requires 66N + 15 characters where N is the number of preferences we have (the main table markup is 15 characters, and then the loop outputting the rows is 66 characters). Thus, if you get bonus points if you can beat 66N + 15. Since CSS implementations supposedly use lower bandwidth than tables at higher orders, assume there are 10 (or even 20) preferences. Thus, if you can meet the constraints and do it in less than 675 characters (or 66N + 15), you get bonus points. To give CSS the further benefit of the doubt, id and class names, regardless of length, will be counted only as 1 character.

..:: Final Note

This is not a work or school project. This is my software engineering side wondering how a lot of the CSS zealotry is supposed to make sense. Also, I personally haven't updated any code on this site since the winter break of 2006/2007, and I know that a lot of the ways that I've done stuff on this site is crap code. This is my own home-grown CMS, with home-grown CSS, and I haven't really been devoting much time to it. In other words, don't bother with personal attacks. I'll just delete them. Post your answer in the comments.

..:: Update

Apparently this is too hard. Try it with float allowed. You'll still have a ridiculous amount of problems doing this simple top-left-top-right-bottom-full (TLTRBF) layout problem.

Post Last Updated: Jan 3, 2008 2:48 pm
Social Bookmarking (?)

StumbleUpon

Comments
Ray wrote on Saturday, 9 February '08 - 8:41:38 PM -0500 [reply]
Nice post.

I think it should have one more constraint (or bonus), to reflect one of the primary real-world concerns:

* Should be completed and tested in all aforementioned browsers within 5 minutes or less (the approximate time it would take using the table). That would include any necessary research time.

Deduct 10 points for every 5 minutes beyond the first, up to an hour, and then 100 points for every hour beyond that. When you reach -1000 points, stop and wonder why you've just spent 10 hours trying to do something that should only take 5 minutes.

Jordan wrote on Wednesday, 16 April '08 - 12:42:53 PM -0400 [reply]
This is a fun and interesting challenge, and is a powerful practical response to CSS zealotry.

However, constraint three is neither realistic nor desirable. It is unrealistic to expect conformance from browsers with a badly broken CSS implementation without special treatment; and it is undesirable because less than one percent of visitors to most sites use a version of IE below 6.0, representing a market segment which is unlikely to wield much buying power.

Also, point five is dubious. Why shouldn't cell three, which is an extended label for the element, be part of the label content for cell one?

djlosch wrote on Thursday, 17 April '08 - 10:44:18 AM -0400 [reply]
i can understand how you'd not care about IE5.

as for #5, the problem with the semantic argument is that in ideal CSS, cell 3 should be an extended label for an element just as you say, and CSS should control where it ends up, regardless of where the tag is put in the html document. it's not so important with cell three though. CSS simply requires that the cells are out of order. you can either put cell 1 inside cell 2, or cell 2 inside cell 1, or cell 2 before 1. if you want things as extended labels, then cell 2 and 3 should be inside cell 1, but CSS just cant do that without ridiculous markup.

Jordan wrote on Wednesday, 16 April '08 - 12:43:40 PM -0400 [reply]
(By the way, what's up with the comment form converting my linebreaks into encoded
s?)

djlosch wrote on Thursday, 17 April '08 - 10:38:17 AM -0400 [reply]
sorry, was changing some stuff around and left a switch turned on for a while.

Add Comment
Name:

Comment:


Please do leave a comment as I love to get feedback from visitors.
  • All fields are required, but your real name is not required.
  • Plain URLs (once again, no HTML or BBcode) will change to clickable links after 72 hours.
  • Comments are of the opinion of their author, not myself, and are not endorsed by myself.
  • Spam will immediately call upon the wrath of the BanHammer.