Tue. May 12, 8:23:09 PM
You can always set both heights to 100% and thus making BODY as tall as HTML, thus it will always hit the 'bottom' of the viewport won't it ?
I've always been interested in the subtle differences between the HTML and BODY elements when it comes to CSS. Many designers reference the two elements interchangeably in their stylesheets. Often times it's perfectly ok to place properties in either one, but there are certain instances where you'll want to chose one over the other.
By default, all major browsers assign the BODY element a margin of 8px. We often see this in CSS resets, setting the margin back to 0px. As far as I'm aware there is no other default CSS applied to either elements other than your usual font-size, color etc. The HTML element, in comparison, has a margin set to 0px. Also neither of the two elements have padding, which is often seen in CSS resets as well.
html { margin: 0px; }
body { margin: 8px; }
Another thing I like to place in my stylesheets is some CSS to always display browser scrollbars. I do this because it annoys me when I browse to one page that has a lot of content and then browse to another page that has little content, and my main content DIV is bouncing back and forth. In order to fix this you need to place 'overflow-y: scroll;' on your HTML element. If this property is assigned to the BODY element, nothing happens and it will not work, thus another big difference between the two elements.
html { overflow-y: scroll; }
In Internet Explorer the scrollbar color properties need to be applied to the HTML element rather than the BODY element in order to work. Safari has also added scrollbar styling in their recent build, so we'll have to see how they implemented this as well.
html
{
scrollbar-face-color: #000;
scrollbar-highlight-color: #ccc;
scrollbar-3dlight-color: #999;
scrollbar-darkshadow-color: #666;
scrollbar-shadow-color: #555;
scrollbar-arrow-color: #fff;
scrollbar-track-color: #ddd;
}
Another major difference between the HTML element and the BODY element is background-colors and background-images. The BODY element mimics the default behavior of a DIV element. It's height relies on the content within it. The HTML element on the other hand, spans the entire viewport regardless of the content within it. If you set a background-image to the BODY element and position it bottom, it may not have the desired effect you intended, while the HTML element's background-image will fall at the bottom of the screen regardless of the content within it.
Probably the biggest take-away from this article would be background-images. I almost always use both the HTML and BODY elements to apply background-images to, and it's good to remember that the BODY element may not always hit the 'bottom' of the viewport.
Know of any other differences? Share your thoughts below...
You can always set both heights to 100% and thus making BODY as tall as HTML, thus it will always hit the 'bottom' of the viewport won't it ?
Kevin, that will work, but the element needs to have it's position set to absolute.
How can you get both images in the Html & Body elements to show in IE6 - I have been trying this for ages without success - Only one or the other will show but not both.
@Dele: It might depend if you set your images to repeat-y or not. The BODY background-image will cover up the HTML background-image in the layer stacking. If your BODY image is set to repeat-y it will by default cover up most if not all of your HTML image.
Site Coded And Designed By Neal Grosskopf Using No Crappy CMS Or Themes