Is it really worth the effort to learn CSS and ditch table-based layouts?
January 20, 2004 10:55 PM
Subscribe
I'm about to design one or more sites I may need to maintain for some time to come. I've always used nested tables and HTML 3 tags to get the job done, but nowadays, CSS seems to be all the rage. I can appreciate some of the advantages it offers [more inside] but given all the questions I've heard about "How can I do XYZ in CSS?" and miscellaneous browser compatibility snafus, I'm wondering whether it's really worth the effort to learn CSS and change all my habits. Convince me? I'm not looking for tutorials or help getting started, I'm looking for arguments in favor of learning the standard, reasons why my life will be easier after doing so. Thanks in advance!
When CSS was first getting off the ground, its appeal was changing stylistic elements throughout an entire site from a central location. But some years later, I have never found myself in a situation where I've needed to do that. I can perhaps see myself using it in place of the
font tag, because it's structurally more elegant, but what else?
At this point in time, any multi-page site is probably managed on some sort of template basis, be it through ASP, PHP, or even something like Blogger or DreamWeaver. The hassle of republishing all my Blogger archives under a new template is nothing compared to (what appears to be) the significant challenge of learning CSS. Am I missing some key benefit that makes it all worthwile? If so I'd really like to know.
Bear in mind that I'm really comfortable hand-coding in old-fashioned html, and it took me some time to get there.
posted by scarabic to computers & internet (16 comments total)
Example: about a week and a half ago, I found myself coding this site. You'll notice images that float to the right of content area headers on a number of pages like that. When I was given the design of the site to convert, those images actually sat all the way across the content area. This wasn't great, and the client saw it and didn't like it. He asked if we could change the images so they were only half as wide and floated right and had some kind of border. Because I'd set up the page carefully using CSS, I added the following to the master style sheet:
.content img {
height: 100px;
border: 1px solid black;
float: right;
}
And it was done across every page in the site. 1 minute of work, versus at least a half an hour where I would have had to resize each image, change align="right" and border="1" on every image tag.
OK, you could have done that with a well-thought-out template system, so another example... on my quasi-webnotebook blog thing there's the border around "like a sleepy golden storm" that I did using nested table markup before I knew better. That mess is:
<table width="310" cellspacing="0" cellpadding="1" border="0">
<tr><td bgcolor="#444444">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td bgcolor="#FFFFFF" valign="middle" align="center">
<font size="-1" class="Narrative">like a sleepy golden storm</font>
<img src="../img/pixel.gif" width="1" height="37" align="middle">
</td></tr>
</table>
</td></tr>
</table>
vs what could have been something like:
<div style="padding: 1em 0; text-align: center; width: 310px;">like a sleepy golden storm</div>
It's easier on the browser to render, it's easier on the coder to code.
There are also some benefits having to do with semantic markup. It becomes easier to make your site accessible to odd browsers (like lynx or stuff used by those with disabilities), and more easily parsed by very stupid entities like machines that only have algorithms and heuristics a programmer gave them for brains. So automated extraction of data, in theory, becomes easier.
But I'd also say: do not drink the CSS kool aid -- don't treat CSS and semantic markup like a religion. Treat them like a discipline while you're learning them, but in day-to-day use, they should be just another tool in the box. I say that because last year I wasted a lot of time trying to get perfect XHTML transitional stuff working for clients who, when it came down to it, just didn't care, because they saw HTML documents as visual presentations, not semantic documents. So I wasted a lot of time that could have been better spent playing the guitar, writing music, talking to friends, and diluted my fee over a larger number of hours than the projects should have taken. And made the project late.... anyway, I won't go to much on with that, because it's borderline advocacy, but I do want to point to an article in progress I'm writing about it (any feedback appreciated).
The final benefit to all this, though, is that I think there's a strong personal benefit from the intellectual exercise of being able to see and understand a document from a semantic standpoint -- much in the same way there is from learning algebra. Even if you only use it rarely, you learn to think in a different way that can be remarkably useful on occasion. So I say learning CSS/XHTML is good for the brain , and maybe the soul. : ) "Geometry will draw the soul towards truth."
posted by weston at 11:37 PM on January 20, 2004