Reputation: 383
I have a 3 column layout with a navigation across the top. The 3 columns is constructed as a side-menu with a container and within that container is another side-menu with a container alongside it.
I'm trying to make it so that all of the divs will scroll within the viewport using overflow-y: scroll
but with my current state of things it seems to be ignored and the whole page is scrolling as a whole instead.
Not sure what I'm misunderstanding. I've constructed a Codepen with my current state of things.
Upvotes: 3
Views: 312
Reputation: 22949
Is this the effect you want?
I removed height
property from outer-container
, inner-side-menu
and inner-container
html body {
height: 100vh;
margin: 0;
}
#app {
background: black;
}
.navigation {
background: cyan;
height: 60px;
}
.route-container {
display: grid;
grid-template-columns: 0.25fr 0.75fr;
grid-template-rows: auto;
grid-template-areas:
"outer-side-menu outer-container";
height: calc(100vh - 60px);
background: magenta;
}
.outer-side-menu {
background: orange;
grid-area: outer-side-menu;
}
.outer-container {
background: yellow;
grid-area: outer-container;
display: grid;
grid-template-columns: 0.25fr 0.75fr;
grid-template-rows: auto;
grid-template-areas:
"inner-side-menu inner-container";
/* added */
overflow: scroll;
/* removed height: 100% */
}
.inner-side-menu {
background: lime;
grid-area: inner-side-menu;
font-size: 144px;
/* prevent horizontal scrolling */
overflow-x: hidden;
}
.inner-container {
background: red;
grid-area: inner-container;
font-size: 144px;
/* prevent horizontal scrolling */
overflow-x: hidden;
}
<div id="app">
<div class="navigation">Navigation</div>
<div class="route-container">
<div class="outer-side-menu">Side Menu</div>
<div class="outer-container">
<div class="inner-side-menu">Inner Side Menu Inner Side Menu Inner Side Menu</div>
<div class="inner-container">Inner Container Inner Container Inner Container Inner Container</div>
</div>
</div>
</div>
Upvotes: 1
Reputation: 2516
You should use max-height:100%
instead of height:100%
. Try changing this.
.outer-side-menu {
background: orange;
grid-area: outer-side-menu;
overflow-y: scroll;
max-height: 100%;
}
.inner-side-menu {
background: lime;
grid-area: inner-side-menu;
overflow-y: scroll;
height: 100%;
font-size: 144px;
}
.inner-container {
background: red;
grid-area: inner-container;
overflow-y: scroll;
height: 100%;
font-size: 144px;
}
Upvotes: 0