The first thing to do is try adding CSS Reset scripts.
for demonstration, I just reset margin and padding to 0 .
CSS:
* { margin: 0; padding: 0; }
Then do not use height: auto !important; , because the browser will calculate the height based on the child, and this is the default value.
Add box-sizing properties so you can define specific elements for a specific area.
And to use the value of border-box . This value will indicate the width and height (and the minimum / maximum properties) of this element, defining the frame field of the element. The width and height of the content are calculated by subtracting the borders and filling widths of the respective sides from the specified width and height properties
The box-sizing property is supported in IE (8+), Opera (8.5+), Chrome (*), and Safari (3).
For IE 6/7, you can use polyfill for box-sizing: border-box Christian Schepp Schaefer
This article is about box-sizing from Chris Coyier .
And this is a complete solution and cross-browser works. Demo
HTML:
<div class="first"> First DIV <div class="second"> Second DIV <div class="third"> <div class="fourth"> Fourth DIV </div> </div> </div> </div>
CSS:
* { margin: 0; padding: 0; } html,body{ height: 100%; min-height: 100%; } div{ min-height: 100%; width:100%; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; -o-box-sizing: border-box; box-sizing: border-box; *behavior: url(pathto/boxsizing.htc); } .first{ padding:50px; background: red; } .second{ padding:25px; background: green; } .third{ background: yellow; } .fourth{ background: brown; }
source share