I came across a weird situation when combining css grid and overflow auto.
When I have 3 elements, the outer element has display: grid
, the middle element has height: 100%
and the inner most element has height: 100%
and overflow: auto
. If the inner element doesn't overflow than the 100%
height is maintained perfectly, but when the inner most element does overflow the auto (i.e. scrollbar) doesn't kick in but instead it behaves like overflow: visible
.
Example 1) Outer container without grid and inner overflows: works perfectly.
Example 2) Outer container with grid and inner overflows: Not working (no scrollbar).
Example 3) Outer container with grid and inner doesn't overflow: works perfectly.
body {
/* the body styles are not necessary to demonstrate the problem */
display: flex;
column-gap: 10px;
}
.outer {
grid-template-rows: 1fr;
height: 100px;
background-color: #0000ff77;
padding: 20px;
}
.outer.grid {
display: grid;
}
.middle {
height: 100%;
}
.inner {
background-color: #ff000077;
overflow: auto;
height: 100%;
width: 100px;
box-sizing: border-box;
}
<div class="outer">
<div class="middle">
<div class="inner">
Some<br>placeholder<br>text<br>goes<br>here<br>...<br>...<br>...<br>...<br>
</div>
</div>
</div>
<div class="outer grid">
<div class="middle">
<div class="inner">
Some<br>placeholder<br>text<br>goes<br>here<br>...<br>...<br>...<br>...<br>
</div>
</div>
</div>
<div class="outer grid">
<div class="middle">
<div class="inner">
Very<br>little<br>text
</div>
</div>
</div>
Interestingly enough, this problem only happens when there is a middle element between the grid and the overflowing elements.
I'm not sure if I'm just missing something basic about CSS grid
or I've hit a weird corner case here, any help appreciated.