Joho the Blog
An Entry from the Archives

« Net neutrality - The video || Back to Blog | CSS »

May 24, 2006

Preparing for CSS

I use a bunch of CSS on this page already, but I'm preparing to make the big jump from tables-based layout to using CSS to do the job. Take a look at the source HTML if you want to see why. It's a freaking mess. Or run this page through a validator. It's hopeless.

Making the small change required to make this site more readable on mobile devices requires making huge changes. So, I've spent a few hours translating this page into a non-table-based, CSS-based layout. Thanks to massive copying of templates (thank you, Web!), I've got something up and running that seems to work. (One enhancement I can't figure out how to do: Have the left and right boxes be fixed in their size while allowing the center one to resize as the user resizes the window. I spent a few hours last night failing to get that to work.)

The new page looks like this one, but the cleanup behind the scenes is massive. But I haven't posted it yet because I'm sure it's going to break every way a page can break. I'll try it later tonight, I think, while some of the US time zones are asleep. [Tags: css html]


I'm trying to get my new pgae to pass the w3c xhtml validator I'm down to a mere 15 infractions. They are of two sorts. First, it doesn't like Movable Type's tags. Is there a "loose" DTD somewhere I should be using? If so, what is the exact and precise syntax? Second, it doesn't like dollar signs and spaces embedded in name tags, as MT insists. So, it flags this line:

<a name="<$MTEntryID pad=" id="<$MTEntryID pad="1"$>

Suggestions? Or should I just learn to love being an outlaw?

Posted by D. Weinberger at May 24, 2006 12:14 PM


Comments

You're describing the holy grail.

Lucky for you - this has been found/built and documented already!

http://www.alistapart.com/articles/holygrail

Posted by: Terrell Russell | May 24, 2006 02:36 PM


There's a number of methods with CSS for having a few fixed columns and a fluid one. Probably the easiest (and one that will match your design goal of content-first) is to give your center column right and left margins that match the widths of your right and left columns. Then us absolute positioning to put your columns where those margins sit.

Something like this:

#center { margin: 0 250px; }
#left { width: 250px; position: absolute; left: 0; top: 0; }
#right { width: 250px; position: absolute; right: 0; top: 0; }

Then you'll create your content with the divs in this order: center, left, right.

You'll probably want to play with the margins a bit. Depending on padding and margins of the elements contained in the columns, things may work better if the width of the side columns are 20px or so narrower than the side margins on the center column.

Feel free to shoot me an email if you need some assistance.

Posted by: Adam Kalsey | May 24, 2006 02:41 PM


Oh, and hte MT tag problem... just ignore it. When you install those templates and actually output the page, those tags won't exist. They're only in your template.

If you want to check for validation on your template, go into MT and create a new index template (call it test or something) and have it output to test.html instead of index.html. Then rebuild that template and run your new http://www.hyperorg.com/blogger/test.html page through the validator.

Posted by: Adam Kalsey | May 24, 2006 02:46 PM


This MT code looks incorrect:

It should look more like:

id=">

That might be part of the problem

Posted by: Glenn Fleishman | May 24, 2006 03:28 PM


> (One enhancement I can't figure out how to do:
> Have the left and right boxes be fixed in their
> size while allowing the center one to resize as
> the user resizes the window.

I've tackled this a couple of times and find that tables are a reliable bet when you need stretchy behavior that is consistent and predicatable across many browser versions.

But nevertheless I'll bite...

Try using a combination of absolute position and "right" in addition to the usual "left", as done here:

http://blog.grumet.net/etc/joho1.html

http://blog.grumet.net/etc/joho1.html.txt (source)

But notice that the fixed column widths do not perform well as the font size is bumped up and down. This can be fixed with font-relative em units:

http://blog.grumet.net/etc/joho2.html

http://blog.grumet.net/etc/joho2.html.txt (source)

...which is vastly better IMHO.

Hope this helps.

Posted by: Andrew Grumet | May 24, 2006 05:00 PM


Also, don't miss Chris Pederick's Web Developer extension for Firefox and Mozilla. It ships with several CSS tools including live editing. It's a tremendous learning tool.

http://chrispederick.com/work/webdeveloper/

Posted by: Andrew Grumet | May 24, 2006 05:05 PM


Post a comment

Guidelines for Commenting

Basically, you can say what you want. (Click here for the fine print.)

If you haven't left a comment here before, your comment may be put into a queue for me to approve. Sorry for the delay. Blame the damn spammers.