Dutch Education
Anne van Kesteren has been educating me about my incorrect usage of CSS in this blog. In XHTML the <body>
element does not fill the entire viewport. So, when I apply a background styling to it, the background also should not fill the entire viewport1.
My design, in which the background applied to the <body>
did fill the entire viewport was an accident, due to a bug in Mozilla. The correct way to achieve the desired effect is to style the “root” <html>
element.
Unfortunately, this will mess up in some stupid browser written by a corporation in Washington State. Anne proposed (comment 10; Anne: your comments really should have permalinks!) the following workaround
html, body { background:#EEE url(/~distler/blog/images/LightBlueTexture.gif) fixed; } html>body {background:none;}
This sets a background image for both the <html>
and <body>
elements and then turns off the background for the <body>
. It assumes that the set of browsers which can correctly style the <html>
element coincides with the set of browsers that understand the child selector html>body
. I’m not sure that’s true (IE 6 ?), but life is too short to obsess about broken browsers. I’m sure someone will let me know if the background is messed up in their browser.
Update (8/24/2003): According to Anne, who’s done some testing, this hack will only work in IE 5.0/Win if there are no spaces in the child selector html>body
. Lord, I hate CSS hacks.
1Strictly speaking, the <body>
element doesn’t cover the entire viewport in HTML either. But the CSS Spec recommends that, for HTML (but not XHTML) documents, the background of the <body>
element be applied to the entire viewport anyway, so that it will work as expected legacy browsers (which don’t recognize styling the <html>
element).
Re: Dutch Education
I prefer this technique:
html { margin: 0;
padding: 0;
}
body { margin: 0;
padding: 1em;
background:#EEE url(/~distler/blog/images/LightBlueTexture.gif) fixed;
}