Stuff & Nonsense Home

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

Blogging And All That Malarkey

Proportional leading with CSS3 Media Queries

Yesterday, Mike Davidson announced the sweeping redesign of msnbc.com article pages. The redesign is especially brave from a traditional news outlet business perspective as it emphasizes readability and enjoyment over page views. But I do have a minor gripe with its typography and set out to find a solution.

msnbc.com’s article pages are divided into two area types. The first, it’s header navigation and branding feels right with its fixed-width layout. The second — the article content getting most the discussion, and the one redesigned for readability — cries out to be fluid.


msnbc.com’s article page redesign

Browsers that support min-width and max-width the article content could easily be made fluid, for example (using my content element naming).

.content { 
width : 80%;
min-width : 640px;
max-width : 1200px; 
margin : 0 auto; }

Even the site’s fixed-width assets, including floated images, videos and other content could be made flexible using Ethan Marcotte’s solution for fluid images

img,
object {
max-width : 100%; }

Which brings me to my other problem. msnbc.com's leading (line-height) of its body copy is a little too open for my taste and, in a fluid layout should be responsive to the width of the columns of text. This problem, of proportional leading, is what holds many designers back from adopting fluid layouts.

Type tip: As the width of the measure (line width) becomes wider, leading (line-height) should be increased to aid readability.

How can we solve this, and adjust the amount of leading as the width of a browser window changes? With CSS3 Media Queries.

I won’t attempt to sell the case for Media Queries. Ethan’s Responsive Web Design does that better than I ever could, and has already inspired two of the best designers I know, Simon Collison and Jon Hicks to make their designs responsive. Instead I’ll simply add my two-penneth.

Proportional leading

First, the Proportional Leading example.

Next the HTML, nothing more than two sections, .content-main and .content-sub. One’s floated left, the other right.

section.content-main { 
float : left; 
width : 57%; }

section.content-sub { 
float : right; 
width : 38%;  }

Finally the CSS3 Media Query magic. As the measures in the main and sub content areas are different, we’ll set individual line-height units for each.

.content-main {
line-height : 1.8; }

.content-sub {
line-height : 1.6; }


Default line-height values (above)

Next decide on the increments where the leading should shift to a new value. We’ll be resetting line-height values in three steps when the maximum browser width is 1000px, 900px and 800px. (You’ll need to adjust these values to suit your own designs.)

@media all and (max-width : 1000px) {
.content-main {
line-height : 1.6; }

.content-sub {
line-height : 1.5; }
}


(max-width : 1000px)

@media all and (max-width : 900px) {
.content-main {
line-height : 1.5; }

.content-sub {
line-height : 1.4; }
}


(max-width : 900px)

@media all and (max-width : 800px) {
.content-main {
line-height : 1.4; }

.content-sub {
line-height : 1.3; }
}


(max-width : 800px)

Using a contemporary browser, one that supports CSS3 Media Queries, re-size the window and watch the leading change. The wider the measure becomes, the more open the leading.

Try Proportional Leading on your own fluid, responsive designs and let me know what you think. Oh, and don’t forget, there’ll be plenty more like this in Hardboiled Web Design.

Update

See also Ethan Marcote’s responsive typesetting example from his A List Apart article where he changes font sizes in response to changes in the measure (but doesn’t also adjust line-height.)

Leave your comment

Chris Casciano

July 1 2010 @ 01:18am #

Nice, nice.

What crazy things are you going to come up with when the time comes that its safe to use vw, vh & vm units?

Guy Carberry

July 1 2010 @ 01:26am #

Is there a link to a demo anywhere in this article? Is my red/green colourblindedness failing me again?

Sounds great though. Will give it a go! Good article as ever Andy.

Stephane Deschamps

July 1 2010 @ 01:31am #

It works well on my FF3.6, and yeah, neat idea.

putting it somewhere inside my head for next redesign, thanks for sharing this idea.

James

July 1 2010 @ 01:41am #

Really interesting stuff.

I think that media queries are going to be a big thing as more browsers support them (IE, I’m looking at you :).

I’ve been experimenting with them on my site to split the text into two columns when the browser reaches a certain width.

Cheers,

James

Tom

July 1 2010 @ 01:47am #

It’s nice to see, but our company have recently decided to stop using fluid layouts for the majority of sites we make; one of the reasons being text measure on fluid sites.

So I’m guessing with this technique you could also adjust the text size with the width?

It’s generally said that the width of your measure should be 60-70 characters, but flexible sites can vary that considerably. It’s also a high level accessibility point on WCAG 2 I believe. So it’ll be great if text could resize, which would result more as a zoom-type layout.

Just a thought! Great article.

Andy Clarke

July 1 2010 @ 01:53am #

@2dforever: See also Ethan Marcote’s responsive typesetting example from his A List Apart article where he changes font sizes in response to changes in the measure (but doesn’t also adjust line-height.)

Craig Saila

July 1 2010 @ 01:57am #

Proportional leading responding to fluid line length is a brilliant idea and one I hope a lot more sites adopt it. Thanks for suggesting it.

At msnbc.com, we use fixed body width because of the flexibility required of the pages to serve a range of add sizes and media formats.  That being said, proportional leading is something we will indeed be playing with.

On a related note, we are using media queries to refine some of the presentation of the site in the iPad (and the iPhone), and I expect to be we’ll doing a lot more with them in the coming months and years.

Ethan

July 1 2010 @ 03:21am #

See also Ethan Marcot[t]e’s responsive typesetting example from his A List Apart article where he changes font sizes in response to changes in the measure (but doesn’t also adjust line-height.

Thanks for the mention, Andy! (Quick aside, though: there actually are leading adjustments in that example. Just nothing quite as sexy as yours.)

David Siegfried

July 1 2010 @ 08:07am #

This makes sense to me, though it hadn’t occurred to me. As I have been playing with an adaptive layout of my own I have been disappointed by the lack of support for percentages. I am not sure if line-height would work as a percentage but it would be nice if I could set a border to something like this -

border: 1% solid rgb(255,255,255);

I wonder if adaptive and fluid grid designs begin to take hold more and more that we will get some better options for having things like line-height be, in some way, proportional to the size of the window. Mainly because it seems these max-width media queries in the wrong hands could make for way too much code than a page truly needs if all device sizes are taken into consideration.

Mike D.

July 2 2010 @ 04:17am #

Great post and suggestions Andy. Was going to forward on to Ashley and team but I see Craig has already beat me to it. I very much like the idea of proportial leading, especially considering the loose leading has drawn some strong opinions from readers.

Unrelated: Might I suggest a different quotation treatment in the comments here? Look at Ethan’s comment, for instance. He’s quoting something, but it just appears with single quotes identical to the rest of the comments so it’s not clear that he is quoting.  Similarly, other comments appear like they are quoting when they aren’t.  Something like a big screened-back quotation mark outside the flow of the comment text would solve the problem.  Also, dropping the standard opening and closing quotes altogether would do the same. Cheers!

Shikeb Ali

July 2 2010 @ 09:16am #

Great article ! learned some new & really nice things. I think we can do some crazy stuff with this. Got some idea ... going to write it somewhere safe before it fly away from my mind :D

Christian Shannon

July 2 2010 @ 05:12pm #

Good article and extremely useful. Been looking to use a solution like this in some of my redesigns. Cheers Andy!

Jonathan H

July 3 2010 @ 09:10am #

Thanks Andy; found the article really helpful!  Makes one think about other aspects of the CSS which could be modifed using similar techniques. Cheers.

Chris

July 7 2010 @ 02:51am #

Brilliant use of media queries! Works great for modern browsers and doesn’t cause any problems for older ones. Was wondering if there is any rule of thumb for line-height in relation to line width.

I know 1.4em is a good basis to start from but wondering about when the line gets longer.

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.