Stuff & Nonsense Home

Where you’ll find designer, author and speaker Andy Clarke. The bastard.

Blogging And All That Malarkey

An appropriate use for CSS frameworks

Could this be the day that I eat my words about CSS frameworks? I’ve been mean to them in the past, written harsh things. I once likened them to instant cake mixes in response to Jeff Croft’s What’s not to love about CSS frameworks?.

In the early stages of the redesign project, the team at New Internationalist asked that the new site be developed using Blueprint, because they were familiar with that framework having used it to make the current site's blogs. They wrote about why CSS frameworks make sense on the New Internationalist Tech blog.

I still think that I am right to be tough on CSS frameworks (and tough on the causes of CSS frameworks). I don't want to reignite the whole framework debate. Let me just say that I think that developing a page layout, either during prototyping or for production code using a pre-packaged framework like Blueprint or grid960 is a bad idea.

Not just because of their presentational attributes (you can work around those), but because they encourage people to conceptualize their markup from a presentational, rather than meaningful starting point. Although these frameworks, and others, have been built on work by Eric Meyer (reset) and Mark Boulton and Richard Rutter (typography), their pre-packaged nature suggests a one-size-fits-all solution. I wrote about this recently in relation to leading and typefaces.

That said, working on the New Internationalist redesign project has made me re-evaluate where using a framework might be applicable. Not for wide-scale page layout but for interface details.

The homepage teaser

This teaser is intended to replace the myriad of colorful (and confusing) internal navigation disguised as advertisements on the current site. The markup is straightforward.

<ul>
<li>[content]</li>
<li>[content]</li>
<li>[content]</li>
</ul>

The teaser must be flexible to handle different numbers of items (columns), item widths and styling. My initial struggle was in maintaining a balance between keeping markup light and meaningful, while at the same time making it simple for the New Internationalist team to update. I suppose it's time for me to eat my own words, but the most appropriate way to keep that balance was to use the framework that New Internationalist are already familiar with.

<ul>
<li class="a-magazine span-9">[content]</li>
<li class="a-subscribe span-9">[content]</li>
<li class="a-shop span-6 last>[content]</li>
</ul>

Although CSS equal height columns might yet make an appearance, I applied a tall background image to the unordered list, specified by a class attribute value that reflects the column configuration.

<ul class="v9-6-6">
<li class="a-magazine span-9">[content]</li>
<li class="a-subscribe span-6">[content]</li>
<li class="a-shop span-6 last>[content]</li>
</ul>
<ul class="v9-9-6">
<li class="a-magazine span-9">[content]</li>
<li class="a-subscribe span-9">[content]</li>
<li class="a-shop span-6 last>[content]</li>
</ul>
<ul class="v6-9-9">
<li class="a-magazine span-6">[content]</li>
<li class="a-subscribe span-9">[content]</li>
<li class="a-shop span-9 last>[content]</li>
</ul>


Teaser variations (View in your browser)

A Fireworks PNG toolkit makes it easy to export background image variations of columns and color schemes that compliments the content.

Allowing for different image widths in current (wide format) articles

As I wrote earlier this week.

The wide format layout for current articles has largely been received well, but the team at New Internationalist have expressed concern about the availability of super-wide images. Most of the images in their library are portrait and would not adapt well to cropping to a letterbox format. Fair point, but I was concerned about different image formats diluting the drama that I hope my layout conveys through its slightly unusual, single column format.

My solution? Define ten possible image widths from 540px to 940px (plus padding) based on the Blueprint alignment grid that underpins the design. With a little auto-margin centering on their container, these image sizes all fit well above the single content column.


Article image variations (View in your browser)

<div class="span-17">
<h1 class="entry-title">If you go down to the woods today.</h1>
<abbr class="entry-issue"><a href="#">Issue 500</a></abbr>
<img src="span-17.jpg" alt="" />
<div class="entry-summary">
<p>There is no easy fix for climate change.</p>
</div>
</div>

How do those words taste?

Well, if CSS frameworks are like instant cake mixes, pretty damn good. I still stand behind everything that I've said in the past about the unsuitability of pre-packaged frameworks used wholesale for page layout. But for small areas that demand regular updating by people who may not be familiar with CSS layouts, from now on I'll consider that an appropriate use for CSS frameworks.

Leave your comment

Vladimir Carrer

June 11 2009 @ 12:39am #

In my opinion the point of CSS Framework(Library) should be making high level reusable CSS code.

The great thing about Grid Frameworks is that you can have so many grid variations. The negative thing is like you sad is “instant cake mixes” or take or leave solution, so if you want different column or gutter size you probably should rewrite everything.

Maybe is it time to start thinking about CSS Frameworks differently, CSS Framework is not just Blueprint but any high level reusable CSS code.

George Terezakis

June 11 2009 @ 01:40am #

I find the approach entirely in line with the “content out” principle. The framework just offers the “structure” layer (.span-6) above the “meaning” layer (.a-magazine). The content stays the same. And the grid notion is good because as the layout requirements keep changing, all the appropriate styles will be there to accommodate them.
I believe that this is precisely the need CSS frameworks were created to address in the first place: they were not supposed to cover all layout needs of all websites.
And of course, nobody should be feeling guilty using them this way, especially you Andy!

John Faulds

June 11 2009 @ 07:15am #

I notice the use of a last class on the last list item. You can probably do away with that by using the first-child pseudo-class instead. Rather than putting the margin (or padding) on the right, you put it on the left and then for .teaser li:first-child you reset it back to 0.

The reason for using first-child rather than last-child is that last-child isn’t supported in IE (not even IE8), but first-child is supported by IE7+ and if you use something like Dean Edwards’ IE7.js, it’ll also work in IE6. (Of course, if you’re using Universal Internet Explorer 6 CSS, then you don’t need to bother about it ;)

Andy Clarke

June 11 2009 @ 07:35am #

@John Faulds: I notice the use of a last class on the last list item. You can probably do away with that by using the first-child pseudo-class instead.

— You’re absolutely right of course. I’m a huge fan of pseudo-classes and under normal circumstances would use first and last-child all the time, supported in IE or not.

But, and there’s a big but, we just don’t know yet which route New Internationalist will take on the IE6 issue, so until then, class=“last” stays, like the fat kid at a party that no one wants to talk to (no wait, that’s Opera ;) )

Anders

June 11 2009 @ 06:20pm #

@John: I’ve also made the same observation. An even better approach would be, if the .last is used primarly for nulling out margins, to use negative margins on the container element. Even lets the fat kids play…

Suppose you have three list items that you would like to separate by 10 pixels and the container is 400px wide:
li {margin-left: 25px; width: 150px;}
ul {margin-left: -25px;}

The list items will now be evenly distributed across the 400px width. display:inline will solve the IE issues, given your list items are floated left.

Commenting is not available in this channel entry.
Hardboiled Web Design

Hardboiled Web Design by Andy Clarke

How the latest technologies and techniques will make your websites more creative, flexible and adaptable. Get hardboiled in all formats from Five Simple Steps. Digital formats also available at Amazon.com, Amazon.co.uk and the iBooks store.

We’ve deconstructed this site to focus on content while we restyle. Expect wonkiness during the transition.