css - Background-Color of BODY tag applied to the whole HTML -


this question has answer here:

i confused size of body tag in html.

i have tough code follows:

<body>  </body> 

 body{         padding: 0px;         height: 100px;         background-color: #e5e5e5;     } 

why background cover of page?, thought should cover 100px,

please explain me, thank help!

this indeed confusing, specified in css 2.1 specification, clause 14.2 background: if computed value of background-color transparent , computed value of background-image none html element (as things default), browsers must instead use computed value of background properties body element , must not render background body (i.e. make transparent). is, body background magically turns html background if html lacks background of own – , affects background properties, not true height of body element.

i haven’t seen rationale odd rule, prescribes kind of “reverse inheritance”. it’s specified in css 2.1 , applied browsers.

as explained in other answers, can make content have background of specific height either setting background on html (so body background applied body only) or using wrapper element inside body , setting height on (since special rule applies body only).

thanks anne van kesteren pointed css spec when asked in whatwg mailing list. (i thought knew css 2.1 heart didn’t. ☺)


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -