I have some questions regarding the following css that I found:
html, body {
height:100%;
min-width:100%;
position:absolute;
}
html {
background: none repeat scroll 0 0 #fff;
color:#fff;
font-family:arial,helvetica,sans-serif;
font-size:15px;
}
- is it necessary to have height and min-width to 100% on the html and body? What’s the benefit?
- what is the reason for using position absolute?
- why did they set the background/color/font on the html and not the body? Is there a difference? Or is it just preference?
It’s usually unnecessary. However, there are a few times where you may need it. For example, maybe your base/site-wide website css file specifies the size to be different (you know those sites where the sides are just borders, usually blogs? Those widths have been resized down). Note that when you have percent it’s of the parent container. So Div A may have
width: 100%but if it’s parent container haswidth: 500pxDiv A will have 100% of 500px.There is no reason for
position: absoluteon the html + body that I can think of. One side effect of absolute positioning is that the element nolonger “floats inline” with the rest of the elements (not sure how you would describe/word this).For example,
position: relativeignores absolutely positioned elements. So if you had Image A (absolute) and Image B (relative) and B hadleft: 10px;, Image B would be offset from the left of the parent, instead of where A would have been. Hopefully I’m making sense here.So sometimes I just set “position: absolute” whenever I have a background image. If it’s the first child, it everything will show up on top of it (since the new elements are “added on top” and ignore the absolute-positioned element).
The body will inherit those properties, and so yes it’s just preference.