Weblogs, with few exceptions, center around words. News, opinions, thoughts, ideas, stories, original writing: all words. Visual design is important, to be sure, but if people can’t read your words, what’s the point?
In the fall of 2000, Jeffrey Zeldman famously said that relative font sizing was impossible (”pixels, baby… or nothing”) because of an overwhelming variety of browser bugs, starting with Netscape 4 and ending in the most modern browsers. Since then, Netscape 4 still hasn’t gotten any better, and it still hasn’t gone away, but at least we’ve all learned a thing or two about taming the browsers and making relative font sizing a reality. (Zeldman too; his recently reincarnated Web Standards Project uses the technique described below.)
Use relative font sizes in browsers that can handle them, and absolute font sizes in Netscape 4, which does not reliably support relative font sizes. You can do this even if you don’t use multiple stylesheets. In a minute, I’ll give copy-and-paste solutions for the default Movable Type template and all default Radio themes. And a lengthy explanation of the technique itself to help you implement it in other templates.
Lillian benefits. Lillian has difficulty seeing web pages clearly, due to nothing more than old age. Like 80% of the Internet population, she uses Internet Explorer for Windows, which does not support resizing text unless the web designer exclusively specifies relative font sizes. Lillian has changed the default text size in her browser (under the “View” menu, “Text Size”), but it doesn’t do any good on sites that use absolute font sizes. This includes virtually every weblog template in existence. For example, this is what the default Movable Type template looks like to Lillian:
If the template used relative font sizes, it would look exactly the same to the majority of readers who don’t need (or care) to change their text size. But this is what it would look like to Lillian:
Again: if people can’t read your words, what’s the point?
In your Home Page Template, look in your <style> section near the top for a CSS rule that looks like this:
body, td, th, p { font-family: verdana, sans-serif; font-size: 12px; }
Keep that just the way it is, but add this immediately after it:
/*/*/a{} body, body td, body th, body p { font-size: x-small; voice-family: ""}""; voice-family: inherit; font-size: small; } html>body, html>body td, html>body th html>body p { font-size: small; } /* */
Make sure to include the comments at the beginning and the end. They’re the key to the whole thing, as explained below.
The default Movable Type template is more complex than the Radio templates, but we’re going to do the same thing, just more of it. In your Stylesheet template (styles-site.css), add this at the end:
/*/*/a{} body, body a, body .calendar, body .calendarhead, body .title, body .sidetitle, body .syndicate, body .powered, body .comments-post, body .posted { font-size: xx-small; voice-family: ""}""; voice-family: inherit; font-size: x-small; } html>body, html>body a, html>body .calendar, html>body .calendarhead, html>body .title, html>body .sidetitle, html>body .syndicate, html>body .powered, html>body .comments-post, html>body .posted { font-size: x-small; } body .date { font-size: x-small; voice-family: ""}""; voice-family: inherit; font-size: small; } html>body .date { font-size: small; } body #banner { font-size: 200%; } body .description { font-size: 60%; } body .blogbody { font-size: 110%; } body .blogbody, body .calendar, body .calendarhead, body .side, body .title, body .sidetitle, body .syndicate, body .powered, body .comments-body { line-height: 128%; } /* */
Again, make sure to include the comments at the beginning and the end.
The general idea is that we’re going to use font-size keywords. These are little-used (due to bugs in older browsers), but they have three interesting properties:
90%, and within that you have a “post” section sized as 90%, some browsers will display the post at 81% (90% x 90%), but some will display it at 90%. With more than one level of nesting (common in templates that use tables for layout), text quickly becomes unreadably small as the percentages compound. However, if your “main” section is sized as small, and the “post” section within it is sized as small, all browsers will display the “post” section as small.small sounds like an absolute size (especially in light of the fact that small nested within small is still small, see above), but it works. What can I tell you? IE/Win resizes text sized with font size keywords. I swear.So we’re going to use font size keywords to specify our basic sizes. And if we need finer control than that, we’re going to use percentages, but only on leaf classes that contain text (so on “post”, but not “main”) to avoid compounding percentages, and not too small, to avoid becoming microscopic when combined with users’ smaller default text sizes.
Here’s the general idea of font size keywords:
p { font-size: 12px; } /*/*/a{} body p { font-size: x-small; voice-family: ""}""; voice-family: inherit; font-size: small; } html>body p { font-size: small; } /* */
There’s a lot going on here, and it’s all important, so pay attention.
x-small. This is a font size keyword which, at default settings, Internet Explorer 5 for Windows will translate into 12px. However, if the user changes their “Text Size” (under the View menu), this text will scale larger or smaller, depending on the user’s setting. This is what we want. (Note: we’ve now defined font-size twice for IE5/Win, but that’s okay, because the more specific selector always wins, and the previous selector is simply ignored.)x-small to 10px, not 12px. Luckily for us, IE5/Win has its own parsing bug that we can exploit: it looks at that odd-looking voice-family and mistakenly thinks that this entire “body p” selector is over, so it ignores all the lines until the “}”.small, which modern non-IE5/Win browsers (the only ones still listening) correctly interpret as 12px (at default settings). Again, if the user sets their “text size” to larger, this text will scale larger, which is what we want./* */. This triggers Netscape 4’s parser to start listening again. If we defined any further rules after these empty comments, all browsers (including Netscape 4) would apply them.To recap:
<p> text at 12px, regardless of user setting.<p> text at x-small, which works out to be 12px at the default setting, but would scale larger if the user set their “Text Size” setting larger in the View menu.<p> text at small, because of the “font-size: small” rule in the “body p” selector. This works out to 12px at the default setting, but would scale larger if the user set their “Text Size” setting larger.<p> text at small, because of the “font-size: small” rule in the “html>body p” selector. This works out to 12px at the default setting, but would scale larger if the user used the “Text Zoom” feature.§
I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)
§
© 2001–9 Mark Pilgrim