#myDiv {
width: 100%
height: 100%;
padding: 5px;
}
----
===== Solution =====
**display:block** is the default display value for a div, but **display:explicit** is also good.
The container has to be the right type; position attribute is fixed, relative, or absolute.
.stretchedToMargin {
display: block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-top:20px;
margin-bottom:20px;
margin-right:80px;
margin-left:80px;
background-color: green;
}
Hello, world
----
Can also do percentage:
*.stretchedMargin {
display: block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-top:1%;
margin-right:50%;
margin-left:5%;
background-color: green;
}
----
box-sizing: border-box;
See: http://caniuse.com/#feat=css3-boxsizing
----
===== Using basic CSS =====
The solution is to NOT use height and width at all! Attach the inner box using top, left, right, bottom and then add margin.
.box {
margin:8px;
position:absolute;
top:0;
left:0;
right:0;
bottom:0}
This will show three nested boxes. Try resizing browser to see they remain nested properly.
----
===== Using Calc =====
#myDiv {
width: calc(100% - 5px);
height: calc(100% - 5px);
padding: 5px;
}