I designed this blog as it currently stands, in all of its fixed-width glory, back in 2008. Since then, as I have gotten a bit smarter, I have been slowing toying with updating some of the specific design elements. None of these are very revolutionary, and some are actually old hat for many, but time available is short in these parts. And what time was available was usually spent on the “getting smarter” part.
The key things that I want to accomplish are as follows:
- Better typography with typefaces from Typekit and a solid vertical rhythm.
- Since grids have become all the rage, get into some of that action.
- A better color scheme.
- Implement footnotes, or better yet, “sidenotes” in the margin , much like Jon Tan and Kilian Muster.
- Make my home page more of a “hub” by including data from my Twitter, Flickr, and Pinboard accounts.
Some of the intermediate steps have been captured in the Lab section of the site. Specifically, the Prototype section is a living (and somewhat documented) work-in-progress of my efforts so far.
Many design professionals extoll the virtues of Photoshop to create comps and then translate those to HTML and CSS. I built some initial comps for type, colors and initial layout, but being that my Photoshop skills are infantile, I found the process long and laborious. I then changed to building an entire site of boilerplates: Home Page, Single Article Page, Archives List. I concentrated on building a proper HTML structure, using new HTML5 elements such as section
, article
and footer
, before adding general and then specific style declarations.
Before I get into any specific elements of the new design, one tool that I have found invaluable in this process has been Sass, a CSS pre-processor. There are tons of tutorials on Sass and this won’t be one of them, but the key improvements I’ve taken advantage of are variables and functions.
Typography
I make no claim to any sort of design skills, but one area that I have studied a fair amount of over the years is good typography. 1. A while ago I created a test page that implemented a vertical rhythm. The key aspect of maintaining a vertical rhhythm is to ensure that the line spacing of blocks of text (leading) and the spaces between text blocks or other elements on the page all equal to (or relate) to a specific value.
Here is a basic example, given a base font-size
of 16px and a line-height
of 1.5, our vertical rhythm is 24px. This example will also use ems for sizing type, so 1.0em = 16px.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
If we wanted h3
headlines to be a larger size, say 18px, we use the formula:
Desired Em Size = Desired Px Size / Context Px Size.
So 18px / 16px = 1.125em. Just setting font-size: 1.125em;
on h3
elements would break our vertical rhythm because the bottom margin of the h3
would no longer be the desired 24 pixels:
1.125em(h3 size) * 1.5em(bottom-margin) = 1.6875em
And 1.675em * the base font-size
of 16 is 27px. So we have to change the bottom margin of h3
(and line-height
) using the same formula:
1 2 3 4 5 |
|
That is all well and good, but if there are more than a few elements with different sizes, that is a lot of math to crank out. When I first started working on maintaining a vertical rhythm, I actually built an Excel spreadsheet to calculate everything:
However, if I decided to change the base font-size
or line-height
for whatever reason, I would have to go back and manually change all the CSS declarations.
Sass to the Rescue.
This is where variables and functions in Sass can make this easy. Here is an extract from the typography section of my Sass variables partial:
1 2 3 4 5 6 7 8 9 10 |
|
The em
function takes two arguments: my desired font-size in pixels and the pixel size of the context it is in. These arguments are variables and the em
function is declaring both of them: $target
and $context
. This latter argument defaults to the $base-font
variable that I declared in the beginning (which is 16px), if I pass it nothing else. In my redesign, here is the declaration for h2
elements in my Sass file:
1 2 3 4 5 |
|
I’ve passed a desired size of 24px to the em
function, which then does the following:
1 2 3 |
|
I have the + 0em
to add em to the returned value since I’m using unitless numbers.
The lh
function is used to help maintain the vertical rhythm. We’ll get to this function in a minute. Here is the CSS that SASS creates for the above article h2
declaration:
1 2 3 4 5 |
|
With SASS doing all the math, and me doing none, I get the desired font size of 24 px converted to ems, and the line-height and bottom margin are also 24 pixels (1em * 1.5em, which is 24px). And 24px is my desired vertical rhythm.
A key aspect of a vertical rhythm is that it is a “rhythm” and not a rigid scale. Bringhurst writes about deviating from a vertical rythym, but doing so in multiples of the base “leading” or line-height
in CSS terms. The lh
function accepts a multiplier as its first argument and the context size in pixels as the second:
1 2 3 4 5 |
|
Here is another example from my Sass typography partial:
1 2 3 4 5 6 7 |
|
I want the top margin of h3
elements to be 36px (1.5 * 24px) and the bottom margin to be 12px (0.5 * 24). These add up to 48px, which is an even multiple of the base line-height
. Let’s break this function down a bit.
Remember that the formula for calculating a desired em size is:
Desired Em Size = Desired Px Size / Context Px Size.
Since I have changed the font-size of the h3
element to 18px, the context has changed as well. Manually calculating the margin would be as follows:
1 2 |
|
The lh
function takes the multiplier (1.5) and the new context (18) as arguments. It multiplies the $base-vr
variable (which I declared to be 24) by the multiplier (24 * 1.5 = 36) and passes the result as the first argument ($target
) to the em
function and passes the second argument (18) as $context
to em
:
@return em($base-vr * $amount, $context)
Again, the em
function is just calculating the Desired Em Size formula: 36 / 18 = 2. The generated CSS for the .entry h3
declarations is:
1 2 3 4 5 6 7 |
|
The line-height
passed a multiplier of 1.0 in order to keep it at the baseline vertical rhythm of 24px. If you never need to deviate from this rhythm, the lh
function is not required and you could just use the em
function to calculate margins for elements that have different font sizes.
WTF?
You could be forgiven for thinking that this is a lot of work, but what if you decide in a week or year to change your default font-size, or vertical rhythm? All that is required to update your initial variables:
1 2 3 |
|
Save your Sass file and…you are done. Every single CSS declaration that uses a em
or lh
function will recalculate in your updated CSS file. A Google search for ‘Sass vertical rhythm’ will return a plethora of pre-built functions and extensions that just need to be included in your own files. Or use mine.
More Sass Typography Goodness
Designer Mark Boulton wrote an article about incremental leading, which is changing the vertical rhythm of elements with smaller font sizes if the default leading is too large. The new rhythm for these elements is not a complete departure from the base line, but is in sync with it by aligning say every 5th line of smaller text with every 4th line of main text (just read the article if that sounded confusing.) Here is a Sass function I wrote that accomplishes this:
1 2 3 4 5 6 7 |
|
Let’s say we wanted sidebar
text to be 15px and use the above example values. Here is the Sass declaration:
1 2 3 4 |
|
With no more effort on my part, other than to hit ‘Save’ in my text editor, the following CSS is output:
1 2 3 4 |
|
Another area where I have found Sass variables to be helpful is with defining font-family
groups like so:
1 2 3 4 |
|
Throughout my Sass files I have declarations such as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
If I want to change the typeface used for titles, rather than search through my CSS file for all affected elements, I just change the $title-ff
variable, which are listed right below my other typography related variables.
Sass has a ton of features such as mixins and the ability to extend CSS selectors, but just using variables and functions has been a huge help in quickly experimenting with different aspects of web typography.
Upcoming articles in this redesign series:
- Using Susy to create fluid grids
- Colors by Solarized
- Creating Sidenotes
- Good web type with Tyepkit
- Leaving Movable Type and the alternatives
-
I can’t recommend enough Robert Bringhurst’s Elements of Typographic Style ↩