How can I create a grid layout with 3 rows so that the rows fill the entire screen, even if the rows are empty?
For example, header and footer have 100px and 50px. The middle grid row (main area) should fill the remaining screen.
.grid {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 100px auto 50px;
}
header {
grid-column: 1/2;
grid-row: 1/2;
background-color: bisque;
}
main {
grid-column: 1/2;
grid-row: 2/3;
background-color: chocolate;
}
footer {
grid-column: 1/2;
grid-row: 3/4;
background-color: darkolivegreen;
}
<body class="grid">
<header>
Header
</header>
<main>
Main
</main>
<footer>
Footer
</footer>
</body>
I’ve read similar questions here but haven’t found anything suitable (I’m also still a beginner in web design).
2
Answers
I think you are missing the
height: 100vh
which can fills the entire viewport height.Try below:
There are 2 solutions, better and worse:
parent
div height and use1fr
grid-template-rows
and determine childrens` heights seperatelyas I mentioned, 1st solution is much more sophisticated so to say…