I've been having problems with implementing a nested grid structure.
This is a simplified example. As you can see the nested structure gives the height for the outer structure, thus growing outside the body.
What I'd like to achieve is to make the .content__inner
element, and only that element scrollable. Everything else should be inside the viewport. How can I achieve that?
Edit 1: Just to clarify, I'm using 100vh on the body, but don't want to set it on the container. The container should have the height of its parent, whatever it is.
body {
display: block;
height: 100vh;
width: 100%;
background-color: white;
margin: 0;
}
.container {
max-height: 100%;
display: grid;
grid-template-areas: "header header" "side content" "footer footer";
grid-template-columns: 50px auto;
grid-template-rows: min-content minmax(min-content, max-content) min-content;
}
.header {
grid-area: header;
background-color: rgba(255, 255, 0, 0.3);
}
.side {
grid-area: side;
background-color: rgba(0, 255, 0, 0.3);
}
.content {
grid-area: content;
background-color: rgba(0, 0, 255, 0.3);
}
.overflow {
overflow: auto;
}
.content-item {
height: 20px;
margin-bottom: 5px;
background-color: white;
}
.footer {
grid-area: footer;
background-color: rgba(255, 0, 255, 0.3);
}
<div class="container">
<div class="header">header</div>
<div class="side">side</div>
<div class="content">
<div class="container container__inner">
<div class="header header__inner">header</div>
<div class="side side__inner">side</div>
<div class="content content__inner overflow">
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
<div class="content-item"></div>
</div>
<div class="footer footer__inner">footer</div>
</div>
</div>
<div class="footer">footer</div>
</div>