The easiest is to use flex .
You should mind that height: xx%;
requires a known height value on parent to be calculated. Here body{height:100%}
is 100%
of nothing (so for the children) since html has no height set.
html,
body,
section{
height: 100%;/* section inherits height value from body which inherits it from html */
margin: 0;
}
section,
.first,
.second,
.third {
margin:0;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
width:100%;
}
section {
}
.first {
height: 10%;
}
.second {
flex: 1;
background:gray
}
.third {
height: 10%;
}
<body>
<section class="main-container">
<div class="first">
// content goes here
</div>
<div class="second">
// content goes here
</div>
<div class="third">
// content goes here
</div>
</section>
</body>
or did you mean center site content in the middle which flex does easily too (same CSS rules but no flex imbrication needed here ):
html,
body,
section{
height: 100%;
margin: 0;
}
section
{
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
width:100%;
background:gray
}
section {
}
.first {
height: 10%;
}
.second {
height: 10%;
background:lightgray
}
.third {
height: 10%;
}
<body>
<section class="main-container">
<div class="first">
// content goes here
</div>
<div class="second">
// content goes here
</div>
<div class="third">
// content goes here
</div>
</section>
</body>