liquid images in liquid layouts
Tuesday August 10, 2004
Although on this particular site I use a fixed-width layout, I’m a huge fan of liquid layouts, as you can see at A1 ProCoat and frimmin.com. The common arrangement of a 640- or 800-pixel-wide fixed-pixel presentation floating in the middle (or worse, slapped against the left side of the window) of an 1200- or 1600- pixel-wide screen works for many situations (as for this site), but they have disadvantages as well. Web pages flow. W3C specifications speak of the flow of the page on the screen, but too many designers IMHO, don’t understand that the Web really isn’t print, and use pixel-perfect designs to try to translate a print message to the screen. Some problems I’ve noticed with these designs are:
- An absurd amount of wasted screen space; This will only get worse as monitor resolutions get bigger and bigger. I recently tested my personal site (all liquid) on a 2560-pixel-wide Mac monitor, maximized (or as close to maximized as Mac allows). It looked just as good as at 800px.
- Frequently, inaccessible text which can not be resized, which is amazing when you consider how many of these sites are in micro text! I propose every site should be tested by its designers for readability after 24 hrs. without sleep. (That would give some incentive to make the text scalable!)
- Frequently, an inability to think in semantic (X)HTML. (Great, you optimized it for a soon-to-be-obsolete monitor resolution, but what about the Palm? Or the cellphone? The Braille reader or text reader?)
Liquid layouts avoid these problems. They adapt to any size screen, they’re more conducive to thinking in terms of document flow rather than print positioning, and they simply “let the Web be the Web.” I can only speak for myself, but I think other designers who are comfortable using liquid layouts are probably also more comfortable thinking in semantic (X)HTML, and basic accessibility. Furthermore, they encourage users to resize, which is a great habit for users to get into, as they are the ones who ultimately know what’s “too big,” “too small,” or “too long” for themselves.
But there are disadvantages with liquid vis-a-vis fixed:
- Line lengths can become too long for extensive reading. (Easily remedied by resizing the browser window.)
- The huge screen resolutions available today, a layout stretched too wide can reveal “holes” or gaps where background images end. However, this can be worked around by using background colors in conjunction with background images, and making sure that the images used blend into the background colors.<”/li>
- A more serious difficulty is that images can break the layout when the window is made smaller.
Richard Rutter of clagnut.com » has done some fascinating work that solves the latter problem. I like his solution » of using percentage widths (with max-width set to actual width) for small and medium images, and overflow:hidden for wide images.
I’ve extensively used this technique on my personal website, The Wild Things of God.
NN4 will choke on a page where there is inline style on images, but this problem is rapidly becoming irrelevant as that browser fades from use.
Microsoft admits non-compliance, recommends Netscape
I’m posting this one a bit late, but on Thursday, June 10, 2004, office.microsoft.com» displayed an unusually appropriate message to anyone browsing the site with Internet Explorer 6.0. It said:
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 5.01 or later or Netscape Navigator 6.0 or later. Click here for more information on supported browsers.
The funny thing is how much I’ve come to agree! Almost anything done imaginatively or creatively with CSS will fail in Internet Explorer 5.0, 5.5, or 6.0. I now code for Mozilla first, then progressively “dumb-down” my CSS for IE versions with the ridiculous hacks and workarounds needed to do what Mozilla, Netscape 7, Opera, Konqueror, and Safari do naturally most of the time.
The frosting on the cake was when I clicked on on the upgrade link, a slightly lengthier message appeared, politely recommending I upgrade to the current version of IE or Netscape and providing links. Microsoft kinda-sorta recommending upgrading to Netscape 7.1? That’s good advice for anyone! Nice to know that even Microsoft’s web designers have problems with their flawed browser. And next time, guys, why not include links to Mozilla, Opera, and Safari?
Squashing the IE bug from hell
I just solved the strangest Internet Explorer CSS bug I’ve encountered to date. Everything looked great in Mozilla, Netscape 7, Safari, and Opera. I had a smart, two-column layout I’d adapted from layouts by CSS geniuses Alex Robinson» and Mark Newhouse». As long as the browser window was maximized, everything was fine. But when it was resized in IE, there were a number of points, usually only a few pixels wide, where the content column simply dropped below the level of the sidebar—completely off the screen. I shuddered to realize that if a viewer happened to have his window sized to any of these “magic” widths (which seemed almost random) they wouldn’t see any content at all, just a header and a menu!
So it began. I searched everything I could for information on this bug, from CSS books, to my favorite CSS sites, to Google searches with every combination of keywords I could think of. Nothing! Nothing I had read could account for this. I tested other stylesheets in my preferred layout. Some broke, some didn’t, and the ones which broke, broke in different places!
So my layout wasn’t buggy, but by now, I was going buggy! At least I could concentrate my search for the bug in the styles rather than the structure. The worst one was the Forest stylesheet (which is the default index page on my personal site.) I had noticed from the beginning that the problem was worse the smaller the window became—the “magic” points were closer together. Finally, I realized it was related to word-wrapping in some hyperlinked movie titles in my most recent post. I tried using Microsoft’s “word-wrap” property, which helped nothing. At odd points, when these italicized hyperlinked words wrapped down to the next line, the content DIV would fall away. Italicized words. (I may be one of the few designers who actually uses the recommended CITE tag for titles, and CITE renders as italics by default.) Not expecting anything, I typed “IE CSS bugs italics,” and found
the page that explained everything».
Italics! How could the bug be italics? Every word processor in the last 20 years has handled italics. as has every Web browser from Netscape 1 on. How could Internet Explorer 6 mangle them? (Answer: it mangles them effectively as it mangles many things.) Sarcasm aside, IE panics when calcuting width for italics in boxes that are beside floats. This is a nefarious problem that seems to be almost unknown compared to, say, the Box-Model bug. Nefarious, because when can you guarantee that your client will not need italic text, maybe a LOT of italic text, whether it’s an extended quote, a long title, or an emphasized sentence? Understanding this potential layout-destroyer should be as well understood as float bugs and box-model bugs.
There is a fix, and it’s not as simple as styling CITE and EM as “font-style:oblique,” (which doesn’t work, in case you were wondering, the bug affects anything with a slanted type). Bruno Fassino explains all that is known about it at this time on a page at the Position is Everything page. My very brief explanation of the fix, which follows, is no substitute for his lucid work, but I think more pages explaining this are desperately needed.
The key is to add styles to the lowest-level block element which contains the italic text. This will almost always be either a P, DL, UL, OL, BLOCKQUOTE, or DIV tag. Often it’s a direct parent, but sometimes, as in the case of my CITE tags within A tags, the lowest-level block is a grand-parent or higher. The styles must be visible only to Internet Explorer for Windows, and not only that, but there are two mutually exclusive stylings needed, one set for IE Win 5.5+, and another for IE Win 5.0.
IE 5.0 Win must make the width of the containing block 100%, and give it the overflow:hidden style. IE 5.5+ Win must give it an auto-sized width, a minimal height, and visible overflow. The stylesheet snippet below hides it from all non-IEWin browsers, and feeds the corrected styles to the proper versions of IE rather painlessly. For details, see IE and Italics Problem» at Position is Everything.net.
/* \*/
* html p, * html dl, * html ul,
* html ol, * html blockquote, * html div {
overflow: hidden;
overflow: visible;
width: 100%;
width: auto;
height: 1%; }
/* */
An alternate solution would be to use IE Win’s conditional comments in the HTML. Peter Paul Koch at Quirksmode» makes an excellent case for using conditional comments rather than parser hacks. I sometimes use them, but sometimes prefer to put them in the stylesheets—they don’t mix well with stylesheet switchers, for instance.