Click here to get back home

Tradeoffs of setting background-color on html vs. body?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Tradeoffs of setting background-color on html vs. body? david.karr 08-19-2008
Get Chitika Premium
Posted by david.karr on August 19, 2008, 12:41 pm
Please log in for more thread options


If in my CSS I set the "background-color" property on the "body"
element, it only covers the background of the elements defined in the
body, up to the current width and height of the page. However, if the
current component set has a resulting small height, this leaves most
of the page with the original background color (white).

However, if I set the property on the "html" element instead, it does
color the entire visible page, beyond the current height of all the
components on the page.

The latter seems like it's going to work better for me, but I'm
wondering if there are any disadvantages of doing this.

This probably won't make that much difference on a real page, as my
current page is just a page to test the JavaScript components I'm
integrating. The real page it gets integrated into will have much more
information, such that the initial page height will be longer than the
initial visible area.

Posted by Harlan Messinger on August 19, 2008, 3:12 pm
Please log in for more thread options


david.karr wrote:
> If in my CSS I set the "background-color" property on the "body"
> element, it only covers the background of the elements defined in the
> body, up to the current width and height of the page. However, if the
> current component set has a resulting small height, this leaves most
> of the page with the original background color (white).

What is "current component set" and what does it mean for it to have a
"resulting small height"?

>
> However, if I set the property on the "html" element instead, it does
> color the entire visible page, beyond the current height of all the
> components on the page.

If the body has a margin, then you certainly do want to color the html
unless you want the body's margin to have the browser's default color.

Posted by david.karr on August 19, 2008, 3:29 pm
Please log in for more thread options


On Aug 19, 12:12=A0pm, Harlan Messinger
> david.karr wrote:
> > If in my CSS I set the "background-color" property on the "body"
> > element, it only covers the background of the elements defined in the
> > body, up to the current width and height of the page. However, if the
> > current component set has a resulting small height, this leaves most
> > of the page with the original background color (white).
>
> What is "current component set" and what does it mean for it to have a
> "resulting small height"?

My test page defines two divs, one of which is initially populated,
and the other is empty. The only populated div is about 100 pixels
high. The rest of the page is blank. There's a big difference in the
result between setting background-color on the html element or the
body element.

> > However, if I set the property on the "html" element instead, it does
> > color the entire visible page, beyond the current height of all the
> > components on the page.
>
> If the body has a margin, then you certainly do want to color the html
> unless you want the body's margin to have the browser's default color.

I want to control the background-color on the entire visible page.

Note that when I googled for questions like this, I found statements
that say it's not recommended to set background-color on the html
element, as opposed to the body element. They didn't say WHY, however.

Posted by C A Upsdell on August 19, 2008, 4:39 pm
Please log in for more thread options


david.karr wrote:
> I want to control the background-color on the entire visible page.
>
> Note that when I googled for questions like this, I found statements
> that say it's not recommended to set background-color on the html
> element, as opposed to the body element. They didn't say WHY, however.

Perhaps this is related to the fact that that some legacy browsers,
which are now extinct, did not support CSS applied to the HTML element.

Posted by Harlan Messinger on August 19, 2008, 5:24 pm
Please log in for more thread options


david.karr wrote:
> On Aug 19, 12:12 pm, Harlan Messinger
>> david.karr wrote:
>>> If in my CSS I set the "background-color" property on the "body"
>>> element, it only covers the background of the elements defined in the
>>> body, up to the current width and height of the page. However, if the
>>> current component set has a resulting small height, this leaves most
>>> of the page with the original background color (white).
>> What is "current component set" and what does it mean for it to have a
>> "resulting small height"?
>
> My test page defines two divs, one of which is initially populated,
> and the other is empty. The only populated div is about 100 pixels
> high. The rest of the page is blank. There's a big difference in the
> result between setting background-color on the html element or the
> body element.
>
>>> However, if I set the property on the "html" element instead, it does
>>> color the entire visible page, beyond the current height of all the
>>> components on the page.
>> If the body has a margin, then you certainly do want to color the html
>> unless you want the body's margin to have the browser's default color.
>
> I want to control the background-color on the entire visible page.
>
> Note that when I googled for questions like this, I found statements
> that say it's not recommended to set background-color on the html
> element, as opposed to the body element. They didn't say WHY, however.

I don't know. But if you have margin: 0; for your body then it's six of
one and half a dozen of the other anyway.

Similar ThreadsPosted
Re: is invalid html 4 strict? June 21, 2008, 1:43 pm
Re: is invalid html 4 strict? June 21, 2008, 6:15 pm
Table border & backgroundcolor May 11, 2005, 4:51 pm
question about the BODY tag in the HTML DTD April 8, 2008, 3:36 pm
[XHTML+XML] html and body size December 10, 2005, 11:04 am
Setting Row heights January 11, 2005, 8:35 am
setting up a store - looking for help August 25, 2005, 7:31 pm
Setting up imgmaps? February 9, 2008, 9:22 am
BODY DIR=LTR March 7, 2006, 9:01 am
Setting a Cell Image October 1, 2004, 3:01 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap