The first important thing, please try to add CSS Reset scripts.
for demo i'm just reset the margin
and padding
to 0
.
CSS :
* {
margin: 0;
padding: 0;
}
Then don't use height: auto !important;
because the browser will calculates the height based on the child and this is default value.
Add box-sizing
properties to allows you to define certain elements to fit an area in a certain way.
And for value use border-box
. This value will specified the width and height (and min/max properties) on this element determine the border box of the element. The content width and height are calculated by subtracting the border and padding 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 a polyfill for box-sizing: border-box
by Christian Schepp Schaefer
This article about box-sizing
by Chris Coyier.
And this complete solution and works cross browser. 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%; /* ie 6 will use this instead of min-height */
min-height: 100%; /* ie 6 will ignore this */
}
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); /* Add the behavior/HTC after every box-sizing: border-box. You must add prefix with a star so IE6/7 can see it */
}
.first{
padding:50px;
background: red;
}
.second{
padding:25px;
background: green;
}
.third{
background: yellow;
}
.fourth{
background: brown;
}