I logged the height and padding values using this code:
jQuery( document ).ready( function() {
console.log( jQuery('body').css('height') );
console.log( jQuery('body').css('padding-top') );
console.log( jQuery('body').css('padding-bottom'));
}); //end ready
This outputs:
20px
0px
0px
If the height of the body is only 20 pixels, why does the entire background of the browser change black when I use this CSS:
body {
background: black;
}
I'm using Chrome as my browser. If you're curious as to how I ran into this question, I ran into a problem of adding a click event to the body that didn't ever seem to fire due to the body's default height.
The main reason is because the HTML takes the background-color of BODY since: The background of the root element becomes the background of the canvas and covers the entire canvas [...] So since the default background-color of HTML is transparent it will take the one from BODY .
The body element is the root-element, and thus, as required by the CSS rules it loses its background style and the background style is applied to the containing canvas (the webpage area in the browser), therefor the entire screen is blue. The other properties stay with the element (e.g. the border ).
To set the background color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <body> tag, with the CSS property background-color. HTML5 do not support the <body> tag bgcolor attribute, so the CSS style is used to add background color.
The HTML <body> bgcolor Attribute is used to define a Background color of a Document.
A long time ago there was something called document.bgcolor
, or something like that, that would let you set the background of the document itself, but that was deprecated.
Instead it was decided that setting document.body.style.backgroundColor
, or in other words setting the background of the body, would also set the background color for the document
automagically, as the document
object has no styl
e property, but it's still visible when the body/html elements does not completely cover the document, that's why the entire page goes black even if the body element does not cover the entire document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With