Please note that you may have been redirected (you might like to make a note of the URL in the address bar of your browser and update accordingly) This is a permanent archvie but is no longer actively maintained. Please visit http://joshuaink.com for the latest updates.
Elastic fantastic, or...
Monday May 2, 2005
...A simple introduction to elastic layouts
I have been wanting to move away from fixed width layouts from some time and I have, to be honest, been skirting around the issue. With all the talk of liquid layouts, of late I thought it was time to take another look at a more flexible way of laying out.
My decision to provide clients with fixed width layouts has never been without a reason, but those reasons are now fading fast thanks to a deeper understanding of "Web Standards" and my increased confidence in Textpattern as a viable solution for people with no HTML knowledge but still wanting to make site updates. Here isn't really the place for that particular discussion though, perhaps another day.
Thinking back to when I made the leap from tables to CSS, I remember, in the beginning at least, sticking with the same basic layout ideas I was using for tables and simply applying them with CSS instead. It seems to me that I can do the same in order to make the leap to elastic layouts, apply the same principals as fixed width CSS design but use ems instead of pixels to do so.
That is really what this post is about, my notes from the process described above. It doesn't concern itself with the "bigger picture" but rather how I have tried to make the transition from pixel-based to em-based layout as comfortable for myself as possible. In doing so I have missed out large chunks of information and, perhaps, I have over simplified things somewhat.
Still, it has helped my thought processes and all I am aiming to do at this stage is break out of what has become a habit with very few reasons why any longer, a bit like smoking! I am posting it here, firstly, in the hope that it may offer a little help to anyone in a similar situation to myself and, secondly, in the hope of getting a little feedback from those already much further down the line.
All credit to Patrick for the wonderful Elastic Lawn and @media websites, which inspired me to at least give it a try. Also to Roger Johansson who's recent conversion to elastic added further motivation. Thanks, again, to Patrick for confirming that my thoughts about elastic design are somewhere near correct, though I must add, he hasn't read this particular post and all errors found here are mine, and mine alone.
Update
I seem to have completley missed Roger's explanation of how he turned his site over to elastic, so in the unlikley event you haven't read it, here it is.
At the time of writing my iBook is still being repaired, and showing no signs of coming back anytime soon. So I have had no opportunity to check the examples that follow on Safari and chums. Please do let me know if you have any problems and I will amend when possible.
Sizing fonts with ems
It was a pleasant surprise to learn that, having read Richard Rutter's post about sizing fonts with ems, I was already 50% of the way to understanding the basics of elastic design. Reading this post gave me all the information I needed in order to cling on, tightly, to the idea of fixed width layouts whilst venturing into uncharted territory. If you haven't tried sizing fonts with ems yet, go read the post, I'll wait...
Laying out with ems
This is the bit that monkeys with my marbles, it just don't not make no sense gu'vn'r, the font size will ultimately play a part in the width of the layout. Fortunately, I am simply on the bandwagon and not part of the vanguard, so I am happy to accept it as fact and save myself the headaches; if those who know, says it is so, that's more than good enough for me, so I'll march onwards!
Referring back to Richard's font sizing post, I thought the easiest thing to do was start off with a nice round "base" number. Taken as read that the majority of browsers have a default text size of 16 pixels, reducing that to 10 pixels seems like a nice easy number to deal with, so that's what I set up, as follows:
- body{
- font-size:62.5%;
- }
What is an em?
I really don't know the definitive answer to that, though I have read many conflicting ideas of what an em actually is. Digging into the full answer will just confuse the issue, so, for the purposes of this demonstration, 1 em is equal to 100% of the "base" number, which I set as 10, above.
Armed with this information, I now want to set up a container div to the equivalent size of 470px and doing this is simply as case of dividing 470 by 10 to give me my em value:
- #container{
- width:47em;
- }
As this first example shows, it's not totally pixel perfect across all browsers, but it's as near as damn it and it's certainly not scaring me off. The only problem is the text is way to small to be easily read, so I guess I can just increase the font size for that div, perhaps to the equivalent of 14 pixels:
- #container{
- width:47em;
- font-size:1.4em;
- }
As the example now shows, this is not going to work because the div starts expanding to accommodate... buggers.
Styling the HTML tags within the container div doesn't have the same effect as above, thankfully. Given that a proper design job gets the full tag by tag treatment anyway, it's no biggie, so:
- h1
- {
- font-size:1.7em;
- }
- p{
- font-size:1.4em;
- }
This applied, a quick look at the next example shows I am where I want to be and, obviously, as a fixed width addict I want to centre my site on screen.
The same principals as for fixed width can be applied: Add a div with an id (in my case usually called "wrap") but use an em value to define the width as opposed to pixels, in this case the equivalent of 770 pixels and, of course, I need to set the margins in the usual "fixed width way":
- #wrap{
- width:77em;
- margin:0 auto;
- }
Again with the example, which looks just dandy from this end.
To finish off I may as well set up a two column layout just to demonstrate the complete job. It's as you'd expect if you did it the fixed width way, and for that reason, I don't think any more code is really needed on this particular demo. It's pretty self-explanatory and uses a similar technique as already explained here. Of course, you can always look at the styling of the final example if you want more detail.
Update
David over at ukthoughts.co.uk has kindly put together an animated piece that shows the final sample in action. see it here. Thanks David :)
So there you have it, my first baby steps towards more flexible layouts.
I'll leave you with a list of articles that are much more detailed:
Bibliography
- Elastic Design by Patrick Griffiths
- How to size text using ems by Richard Rutter
- Ideal line length for content by Russ Weakley
- About fluid and fixed width layouts by Roger Johansson




Graham Bancroft
1194 days ago
Graham Bancroft
1194 days ago
Gabriel Mihalache
1194 days ago
Graham Bancroft
1194 days ago
Graham Bancroft
1194 days ago
Tristan Dunn
1194 days ago
Tristan Dunn
1194 days ago
Daniel
1194 days ago
paul haine
1194 days ago
Schultzy
1194 days ago
Graham Bancroft
1194 days ago
Schultzy
1194 days ago
Matthew Pennell
1194 days ago
Dave
1194 days ago
Andy Stones
1194 days ago
Matthew Pennell
1194 days ago
Bob Rackers
1193 days ago
Bob Rackers
1193 days ago
Andy Stones
1192 days ago
Joost van der Borg
1191 days ago
Tim
1191 days ago
Tim
1190 days ago
Bob Rackers
1190 days ago