I am trying to get a hold of the CSS Grid, a transition from previously using the Bootstrap that I'm used to.
I created a simple layout (4 rows & 6 columns) however, there is an unwanted whitespace on the bottom, causing a visible scroll.
Is there a way to fix this without setting the exact height to the .container element? When I set the height to the .container (height: 500px), the problem goes away. Is this the way to go around it? I don't want to use a quick fix that will cause me a problem down the way maybe on smaller or larger viewports.
.grid{
display: grid;
position: relative;
margin: auto;
grid-template-areas:
"nav nav nav nav nav nav"
"logo logo logo logo logo logo"
"main main main main main side"
"footer footer footer footer footer footer";
grid-template-columns: repeat(6, 1fr);
grid-template-rows: 50px 50px 1fr 1fr;
}
.nav{
grid-area: nav;
background-color:green;
}
.logo{
grid-area: logo;
background-color:salmon;
}
.main{
grid-area: main;
background-color:cadetblue;
min-height: 800px;
height: auto;
}
.side{
grid-area: side;
background-color:lightpink;
min-height: 800px;
height: auto;
}
.footer{
grid-area: footer;
background-color:sandybrown;
height: 50px;
}
.overlap{
background-color: hotpink;
grid-area: 3/ 3/ 3/ 4;
z-index: 5;
}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSSGrid</title>
</head>
<body>
<div class="grid">
<nav class="nav"></nav>
<div class="logo"></div>
<div class="overlap">
<h3>Overlap!</h3>
</div>
<section class="main"></section>
<aside class="side"></aside>
<footer class="footer"></footer>
</div>
</body>
</html>
grid-template-rows: 50px 50px 1fr auto;
works. I also noticed that for it to work well I have to set a specific height to the element that is ocupying the last row to:..footer { grid-area: footer; height: 50px; }
– Cafeteria