While trying to catch up on my e-mail, I received one from Tim who mentioned he had a problem with the gargoyles layout. He had an image, say 200px wide, sitting in the right column. When a browser window was narrowed to the point that column was too narrow to contain the image, the column was pushed down below the content.
This is one of the big problems (if not the biggest) with fluid layouts. Fluid layouts work great as long as the browser is wide enough to allow the fluid elements to contain their content.
What is a fluid layout?
Really quick to make sure we’re all on the same page. A fluid layout is where the layout’s dimensions (typically the width) is based on the width of the browser. So if a user has their browser maximized on a 1024×768 desktop, that layout will expand to use up all 1024 pixels across the screen ( … of course you have to take into consideration the size of borders and scrollbars and such, making the actual size of the layout more like 980-990 pixels wide, but with fluid layouts you don’t rely on pixel values anyways, so this doesn’t really matter. :)
This is especially good for users who have very very large resolutions (1600×1280 anyone?). Imagine a website where the width of the layout is fixed at 600 pixels. Mr. 1600×1280 is going to have over half his screen left unused. It’s wasted space.
So the upshot of a fluid layout is it conforms to the user’s screen, and doesn’t force the user to conform to yours. I like that very much.
But your layout’s dimensions (width of a given column, etc…) is all based on the width of the user’s window. So if a user shrinks there window to a very narrow width, that browser is going to try and fit your website’s content into that narrow area. It won’t fit, and you start to see the layout break.
A fixed width layout defines how wide it must be. The browser that is narrowed below the fixed width value will simply generate a horizontal scrollbar. The layout remains as intended, but the user has to horizontally scroll. Isn’t this just as inconvienent as a broken fluid layout? Maybe, but I don’t think so.
Onto the matter at hand…
My layout is bursting!
The gargoyles layout is especially unique in that not just 1 column is fluid. Both the middle and right columns are fluid. Both columns shrink and expand as the browser window does. (The left column is fixed at 14ems, which is actually kind of fluid in that as you change the default font size, the width of the left column increases. But that has nothing to do with what I’m talking about.)
Fluid elements, fluid layouts, etc.. they all run into the same problem. As I’ve already said (twice now? or was it three times?) if the browser window’s width is made too narrow, that a fluid element is not wide enough to contain its content, then the column is going to be pushed down because it’s a floated element. This is to be expected since that is how floats work. So when using a fluid layout, or any layout with a fluid element, you need to keep this “issue” in mind.
Okay, so how do we fix it?
The simplest solution is to just not use anything with a static width, like an image, inside a fluid element. But you don’t want to bore your readers/users do you? So we’ll have to do something to let images work regardless of window size. Incidentally, text can trigger this “issue” as well. Set a column 50px wide, increase the font size to some insane value like 1000%, and even a small word like “hello” is going to be too wide to fit. So even sticking to just text really won’t work.
Min-width might work, but IE doesn’t recognize that CSS attribute; so scratch that idea.
Well we could set a static width on the right column. Set it at 220px or something similar, and just make sure you and any other content providers understand nothing wider than 200px can go into the right column.
This works rather well, actually, and is what I suggest most people do. So do that, and don’t read any further, because I’m only going to confuse you.
Seriously, stop reading.
Okay, but remember, you asked to be confused!
Controlling individual elements in the manner described above would be nice because it would allow for more … “fluidity” because if you have more than one fluid element, as soon as one hits its min-width limit, that gets locked at that min-width allowing other fluid elements to continue shrinking. Applying a global width lock (locking the width of the body element, for example) as soon as the first fluid element hits its limit wouldn’t be as efficient as other elements won’t be able to shrink to their limits, resulting in a page that doesn’t go as narrow as possible before applying the width lock.
So what about Tim’s case?
Well, I suggested we make use of the min-width emulation. Calculate out what the min-width for the whole layout is to keep the right-hand column from going too narrow to contain the image in question. The default width for that column is 30%. The math here is simple,
image width / column width or
200 / .3 which gives us 667 pixels. Now there’s some gray area between IE and FireFox box models and how widths are calculated, so to make things simple, I’d add on an extra 20 or so pixels, and just to keep things whole, I say add 33 and give us an even 700 for the min-width value. At that point the right-hand column will never go more narrow than 200 pixels.
That is what I suggested.
Now what about that stuff about controlling min-width values for individual elements? Can I put something together for that?
Thing is… that gets really really tricky. Because of how contorted my CSS can get, it’s not just a matter of altering the width property on a given element. I have to start paying attention to margin and negative margin values on other elements to make sure a correct amount of space is reserved for the right column. Things get very complicated very quickly. It’s an interesting idea, but not one I’m going to attempt anytime soon.
Besides, I’ve drained my brain on this one, and I’m out of steam.
So there you go. Hope it wasn’t too much of a mindless ramble.