Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling the `<html>` element in CSS?

Can anyone explain to me why can we style the element html?
What are differences between it and body?

I usually see tutorials and multiple websites using body and never html, I only found about it when using YUI 3: CSS Reset since changing the background in body didn't work.

Edit: Actually, I still haven't found the problem regarding that, when I add the reset.css the background gets white, when I remove it returns to normal. Yet Chrome inspector says that the background is the normal one. Btw, this is getting off topic. :p
Edit 2: The culprit was the doctype. Somehow it made the html style in the css-reset render after the body style in my stylesheet. Maybe I should open a question regarding this.

Doctype: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

like image 638
Diogo Gomes Avatar asked Apr 07 '10 14:04

Diogo Gomes


People also ask

How do I style a HTML element in CSS?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section.

How do I style a body element in CSS?

To declare style rules for the body of a webpage, you will need to create a CSS rule for the body tag selector. These rules will then be applied to all elements that are placed inside the opening and closing <html> tags that you added to the index.

How do I style a div in CSS?

Use div in CSS Art In the CSS, select the div with the class attribute, then set an equal height and width for it. You can make a circle with the div tag by coding an empty div in the HTML, setting an equal height and width for it in the CSS, then a border-radius of 50%.


1 Answers

Quite often you'll find people styling the HTML element since it does have an affect on the way the page is rendered.

The most notable style you're likely to see is

html,body{    min-height:101%; } 

This is used to ensure that the scroll bars in browsers like Firefox, always show on the page. This stops the page shifting left and right when changing between long and short pages.

like image 195
Jamie Dixon Avatar answered Oct 13 '22 07:10

Jamie Dixon