If you want the .child
element to fill the entire height of the screen, follow these steps:
Set the body height to 100vh - where vh
represents viewport height units, with 1vh being equal to 1% of window height.
Set the height of the container
to 100% of its parent, in this case, the body
.
Set the height of the child
to 100% of its parent, which is the container
.
body {
height: 100vh;
}
.container {
height: 100%;
}
.child {
height: 100%;
background: orange;
}
<body>
<section class="container">
<div class="child">
//content goes here
</div>
</section>
</body>
Here is an alternative solution where the height of the child is not bound by the container's height. (Different backgrounds and widths/heights are added for a better visual appeal)
body {
position: absolute;
width: 80%;
height: 80%;
border: 1px solid green;
background: lightgreen;
}
.container {
width: 20%;
height: 100px;
background: teal;
}
.child {
position: absolute;
width: 50%;
height: 100%;
margin: 0 auto;
left: 0;
right: 0;
top: 0;
background: orange;
}
<body>
<section class="container">
Before content
<div class="child">
//content goes here
</div>
After content
</section>
</body>