I have the following mark up,
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
min-height: 98vh;
color: white;
background-color: black;
border: 1px solid green;
}
#root {
min-height: 100%;
border: 1px solid red;
}
</style>
</head>
<body>
<div id="root">Testing.</div>
</body>
</html>
The div with #root
id has body as its parent which has a height of 98vh
. The div with #root
id has a height of 100%
but it is not getting the 100 percent height of body. What am I missing here?
3
Answers
Just use
height
instead ofmin-height
.Try
inset:0
to let the div relative to its parent.There are multiple ways to get the full height of a child element based on the parent element.
Solution 1
Just use
min-height: inherit;
in child element css, it’s use parent’smin-height
value.Solution 2
You can use
height:100%
in chid element if patent have also fix height value.