Liquid Elastic Layouts
- Mathias Bynens
- huphtur
- Ethan
- Jop
Sizing is easy
‘That’s a gutsy statement, mistuh.’ I know. But it is.
By now, you’ve all been told the usage of ems for liquid widths, you know about maximum widths for capable browsers. The real trick is in the correct usage.
Imagine…
You want a layout that resizes with the window, but make it resizable with ems. Simply put, a combination of Elastic Lawn and a liquid layout. Easy concept, I’ve worked it out for ya.
The beginning is easy. I hope you have set your font-size? You didn’t. Well, say, something like body { font-size: 10px; } will do the trick. Why 10px? That’s easier to measure with. Set your content box or whatever the piece of layout is called that you want to size dynamically to a tasty width of 90% or something like that.
The box will now resize according to the screen size. But, of course, that’s not what we want. You could end up have line-widths of 1500px, and believe me, that’s not nice. And the danger is also in 640×480. Your box will be tiny. And that makes it like really hard to read!
But, there is a way to prevent this. Normally, what you would do is set the min-width to a nice pixel value, like 600. But that, again, is not what we want. We want a layout that can zoom. Zoom is key. min-width: 60em; will make this the minimum width (in most browsers), but it’s zoomable! So people with bad sight can resize the text and the line-width and keep it all normal.
The maximum width is something you might want to think about. I usually don’t go above 1000px. So make it this: max-width: 100em;. Now, people with a screen resolution of 1600×1200 (or those lucky bastards with the Apple 30") will have a quite readable page. And, more importantly, people with bad sight can zoom and have their maximum width expanded. Funky eh?
Now, when people with big monitors (maybe… because they have really bad eyes!) toss their browser full-screen, with an astonishing 1600×1200 or whatever you people use nowadays, the content width stops at 600px, or, to be certain, 60em. But hey, since they have bad vision, how about resizing the whole shebang, to a 15px font-size? The width expands, and the content remains its relative line-width. Ideal, ain’t it?
Final result
Of course, what does it look like? I’ll give you the short answer: check this. Use it at your own risk.
Let me know if it works, and how well it performs for your purpose.
Hiccups
As we all might know, IE doesn’t support max- and min-width, but there’s a hack available for just that, be it with a Javascript. I hope people use a good browser, and this trick relies on that.
Zooiblog