Tag: css

Jump to:

Article

What my recent redesign taught me about CSS

May 23 08

Repeat visitors (welcome back, both of you!) may notice a few things have been pushed about here on the site. I’ve been chipping away at this design for the better part of two months’ worth of spare time. So you’ll indulge me a bit of discussion. There’s just no way around it, boring as they may be, these sorts of posts are a necessary evil.

Less strict / Citation needed

I’ve decided to switch from XHTML to HTML 5. I was initially hesitant. HTML 5 felt like a cop-out. I’d spent all that time being strict, poring over validator messages. Was I willing to throw that time and effort away?

I guess I had never really understood why I was using XHTML vs. HTML. I suppose it was just because that’s what everyone else was using, and they probably knew better than me. Also, it was a badge of honor to know that my site validated against a stricter doctype.

I’ve lost track of the address, as it’s not on the WHATWG site as far as I can tell, but a little while back I read an article about why HTML 5 was being constructed. It made sense. The gist was that XHTML, particularly XHTML 2, was ill-suited to the purposes of many websites.

The real reason though, the real tipping point, was something incredibly small. One tag, actually. A tag most folks don’t even use regularly: <cite>. In contrast to the W3C, HTML 5 has a very clear definition for the use of <cite>. It’s for titles, and titles only. This is exactly what I wanted. The word “cite” might make sense for the source of quotes, but it’s a stylistic nightmare trying to determine which one gets italicized and which one doesn’t. So, that was it. I was going with the spec that had a better description of <cite>.

pre-cisely

Following the guidelines established in Richard Rutter’s A List Apart article on the subject I’ve set the font sizes in ems and done my best to maintain a steady vertical rhythm.1. Keeping the base font size as whatever the browser uses as a default — generally 16px — I calculated the desired size for text-containing elements such as <p>, <h1>, and the like. I tried not to set the font-size on any <div> containers. This kept me with a standard 16px em from which I could determine margins and paddings.

1 Within reasonable limits of my sanity. Certain elements just proved unwilling to concede at which point I ever so eloquently said “Fuck it! It’s good enough.” At least the text you read will be pleasantly configured.

Then I got to the <pre> element and things started acting funny. In one of my test cases I threw a bit of <code> inside a <pre> the way I would expect to do were I sharing some snippet. When I loaded this test in Firefox I was curious to see the text rendered quite a bit smaller than I had expected.

I didn’t set a font-family nor a font-size on the <pre> because I didn’t really see the need. It was just a box that honored line-breaks. I’d be filling it with <code> elements almost all of the time. I’d already set a font-family on those. Besides, if I changed the size that I wouldn’t be working from the standard 16px size and I’d have to refigure my margins and paddings. Using child selectors, I’ve set the size of <code> elements only if they are children of <pre> elements. It looks a bit like this:

pre code {
	font-size: 0.875em;  /* 16px x 0.875em = 14px */
}

Only, in Firefox, instead of 14px I was getting something in the neighborhood of 11px. After some consternation I realized that Firefox (and likely other browsers) sets up <pre> elements as fixed-width elements. By default, these have a font set at 13px. Sure enough, when I put plain ol’ text in there it came out at 13px.

I wanted a solution that didn’t involve setting a font-size on <pre> elements. After puttering about for a brief while, I came up with one.

pre {
	font-family: inherit;
}

This little line caused the <pre> block to pick up whatever is set by its parent, either a <div> or the <body>. Text inside won’t be fixed width by default nor will it be 13px unless told explicitly to be so.

Relatively speaking

One of my favorite additions to this version of the site is the sidenote, seen above. In fact, that note is one of the major driving forces behind the redesign. I’d just become interested in adding notes of some kind to my writing. I’m not entirely happy with the idea of footnotes in HTML. They work in print because a print page is designed with a specific page size in mind. But where to put them at the bottom of an ever changing landscape? On a page that might have any number of disparate posts?

So, this site uses sidenotes. They’re floated off to the left using negative margins. Negative margins feel pretty solid to me. I’ve had the heebie-jeebies about absolute positioning for years. Absolute positioning, I feel, is best left to scripting. Notes are styled like so2:

2 Oh lordy! It looks so crazy here in public. I swear these numbers seemed reasonable at the time.

.note {
	float: left;
	font-size: 0.75em;
	margin-left: -15.083em;
	text-align: right;
	text-indent: 0;
	width: 13.3333em;
}

Care to guess which major browser choked here?

notes on Internet Explorer 6 with and without position relative set

Figure 1 Internet Explorer 6 with position: relative (left) and without (right).

What you see above is a series of screenshots of a very early version of the site on Internet Explorer 6. The shot on the left is what the note is supposed to look like. The shot on the right is what I actually got using the code above. The text of the note just dropped off the face of the earth in IE 6. Increasing or decreasing the text size didn’t do anything. Nor did altering the size of the browser window. It was just gone. Except for the index.

The note indices are relatively positioned a little bit above the baseline. I’m not using <sup> tags because those are presentational and discouraged. When I saw that little one sitting there amongst a missing note it didn’t take long to figure out that relatively positioned elements showed up just fine. Everything else was swept away.

The solution, of course, was simply to add position: relative; to the note styles. Notes are now floated left, and positioned relatively to themselves. But since we haven’t added any actually positioning, they don’t move.

.note {
	float: left;
	position: relative;
	font-size: 0.75em;
	margin-left: -15.083em;
	text-align: right;
	text-indent: 0;
	width: 13.3333em;
}

In summation

So, that’s the obligatory redesign post. I reserve the right to continue to discuss CSS and HTML, but I’ll try my darnedest to find some kind of hook, as I tried to do here. Don’t worry, I’ll get back to the cross stitchery as soon as feasible.

Tags

On the grid

Mar 26 07

I’ve been toying with the use of ems—a typographic space typically equivalent to the width of an upper-case letter M—to define the width of my columns for a while now. I’ve been doing this to create elastic designs wherein the body text is of a comfortable width. I’d like to think I’ve succeeded in some small way, though I’ll always have room for improvement.

The benefit of using an em as a unit of measurement is that an em is based on the width of text itself. As text size is altered by stylesheets, by scripting, or by user agent controls the number of characters in any given line doesn’t change. By contrast, percentages are based on the width of the parent and pixels are static and unchangeable. A change in text or window size in which the containing element has been set in percentages or pixels will cause the text to shift. This may create a paragraph that is uncomfortable on the eye as it is too wide or too thin. Without also altering line height the overall appearance of the text might be lessened. To illustrate the advantage of setting column widths with ems I whipped up this quick little example page

Without knowing it I had been working towards a typesetting standard that has been used with success for centuries: the grid. To be fair, my use of the em has no particular connection to the grid. I could have just as easily been working with pixel measures and arrived at this point. Because my primary concern was a comfortable reading width I found it quite reasonable to consider the rest of the page equally.

Grid systems for the web

Two excellent slideshows from South By Southwest Interactive 2007 have been posted to the web. In Web Typography Sucks Richard Rutter and Mark Boulton describe the dismal state of online typography and what can be done about it. It includes a section on grids. In Grids Are Good Khoi Vinh constructs a fake web portal on a grid. Both presentations demonstrate how much more pleasant your content can be when applied to classic rules of layout and style.

Inspired, I whipped up a few simple background images that you can use to put your own sites on grids. In the archive you’ll find a number of small images designed to be tiled as background images. It has columns from 3 em to 6 em (with 0.5 em gutters) for text size equivalent to 12 px. It also has line height guides for most of the common heights. Set them as the background image on a containing element to help fine tune your grids.

Download: gridtools.v1.00.zip

These were developed specifically for a project I’ve been working on for the past few weeks and may or may not be of use to you. Try them out, see if they help you, and drop me a line if you have any comments or complaints.

Tags

Now that's just embarrassing, Microsoft. Even for you.

Jan 17 07

Normally I wouldn’t even be using Internet Explorer, particularly not the long dead Mac version of IE 5.2. The wife still has it installed on her iMac as she needs it for one of her professional organization sites (the sheer design idiocy of which often baffles the mind). I had launched it because I was hoping to sneak past the lame ass browser sniffer used by my employer’s equally lame ass employee self serve site to check for my W2.

(I didn’t make it, as it is specifically tailored to look for Internet Explorer 6.x and that alone. Using a Firefox user agent spoofer got me through the front gates but I still was unable to access anything but a cryptic error message.)

In the process of trying to get inside I was redirected to Microsoft.com to look for a nonexistent update to my IE browser. Microsoft’s website also uses yet another lame ass browser sniffer to serve up CSS. As it turns out, not even their own ancient browser made the list and what you get when you log in using IE 5.2 for Mac is a stylesheet-free pile of poop that looks like it might have been developed for Mosaic.

microsoft.com as viewed by MSIE5.2 Mac

Don’t happen to have the decaying corpse of IE 5.2 Mac cluttering up your hard drive? You can see a very similar effect if you try to join “The Social” over at zune.net using Camino. (Tip o’ the hat to Grotto 11’s Peeve Farm by way of Daring Fireball for that one.)

Tags

I've made a few changes around here

Nov 27 06

If you’ve been wondering what happened to that Wii post I mentioned last week, well I got a bit distracted. I got to thinking that I could stand to make a few changes to the stylesheet, which led to a few changes to the page construction, which led to not wanting to write the Wii impressions nor anything else until I had updated the site. Now, perhaps, things can continue in their normal fashion.

Comfortable Text, Elastic Design

My first priority was text, as the majority of the web is text. I based my text redesign on The Elements of Typographic Style Applied to the Web. I eliminated the default margins applied to the top and bottom of paragraphs, set a standard line height, and altered the text indentation to only subsequent paragraphs. I feel that this creates a much healthier flow similar to printed works.

The divisions, which I have reduced to as few as possible to maintain the site design, are based on ems rather than pixels or percents. As the text size is enlarged or reduced using the normal browser controls the site layout will shift accordingly.

Goodbye Categories, Hello Tags

Gone are the categories that TextPattern uses to organize content. It isn’t that I think these are broken, I just found that my posts tended to not fit the categories I had defined. Not to mention, my choice of category names left much to be desired. Now, each article or photo has a set of tags that describe its contents. Clicking any of these tags will produce a list of articles or photos tagged with that keyword. In the future I plan to go back and associate tags with the past articles in order to bring them up to speed with this new organizational system.

The Archive is on Hiatus

I am still debating about how to present the archive and as such it has been temporarily removed from the sidebar. With the removal of categories it no longer seems appropriate to sort the archive in that manner. It will be back shortly.

Broken IE Compatibility

I certainly do not aim to disorient the users of the world’s most popular browser, but I refuse to make use of crippled binary transparency just because IE doesn’t support alpha transparency without hacks. I’m working on installing those hacks to reduce the ugliness of the PNG fade and quote mark. Besides, there’s really no excuse not to be using Firefox or Opera.

So, there you have it. A new dawn is breaking on Sorrytown, USA. Or something.

Tags

Curse you, buggy browsers!

Oct 10 04

Okay, when I said I wasn’t going to bother trying to fix things for the PC version of Internet Explorer I was being a bit shortsighted. I mean, was it realistic to think that I could ignore the most common browser in the world out of sheer spite? That’s just crazy talk.

(Besides, I’d like to be able to look at the site at work, just to assure myself that my creation was there. I’m stuck with IE 6.0 and a Windows box. Not much I can do about that, it’s work.)

It seems as though I’m suffering from the Peekaboo Bug. I’ve run into this before, and I don’t quite recall how I fixed it then. I’ve gone ahead and applied the Holly Hack to what I assume is the offending float. Did it work? I don’t really know yet. I’ll have to find a Windows machine to test it out.

It very well might not have. I seem to have a problem with my centered images too. See, what I did was give them the following style:

#content img
{
	display:  block;
	margin:  5px auto;
}

That display: block; seems to be causing some problems for IE. I’m not sure what, precisely. Seems fairly straightfoward (And yes, I know that IE 5.5 and earlier will not be centering the images. I can live with that.), but when I take it out the text in the middle doesn’t go anywhere, but the links on the right still come and go as they please. . .

Sigh. Sometimes it hardly seems worth it.

P.S.

So, the Holly Hack worked pretty darned well at clearing up the disappearing right hand side links, and possibly helped the content part stay where it’s supposed to be. That centered image, which does, in fact, seem to work in IE 6.0 still causes problems with the previous paragraph, and I’m sure the staff page is still ten kinds of messed up for IE users. Either I forget about centering images or I forget about IE. I can’t bring myself to use any more hacks to correctly center these things, they get pretty darned complicated, actually.

Tags

Re: the disappearing/reappearing text

Oct 07 04

Chances are if you’re looking at this site you’re using Internet Explorer. You don’t have to be ashamed. I used it myself for many years. There was a good long while when IE was the only game in town, or at least, beat the pants off of the antiquated competition.

But, times have changed. I mean, when is the last time Microsoft bothered to update IE? It’s been years since a significantly new version. There are still any number of very simple rules it just can’t seem to grok.

For instance, you may notice that there’s no text on the previous entry until you mouse over the title or scroll down at which point it magically appears as if sprung out of the aether. I guess it’s got something to do with the way I styled the images. There ain’t nothing wrong with it. Everything validates just peachy. It ain’t the markup or the stylesheet’s fault.

What I’m saying is this: I’m not going to run myself ragged making sure this is visible in every browser. Even if “every browser” happens to be codeword for “the most popular web browser on the planet.” I mean, if you care about your Internet it might be time to think about a change.

Tags