overflow-y auto does not work
Hi everyone, I'm trying to make the content scrollable using overflow-y-auto, but it's not working as expected. Here's my layout structure
4 Replies
Can anyone help me?
Your content element (with {children}) doesn't have a defined height so it will just get taller according to the content, eventually being clipped/hidden by the parent overflow hidden.
For overflow-y: auto to work the browser needs a specific height so as to decide whether to show the scroll bar or not.
On your top parent element, try swapping out :
grid-rows-[auto_1fr]
for
grid-rows-[auto_100%]
This would normally cause a scroll bar as "auto" (height of header) + 100% > 100dvh however, as you have defined overflow-hidden on the parent element, this is negated.
Why does 1fr not work?
fr
calculation is deferred until all other elements are sized so the exact value is not available when the browser decides whether it needs a scroll bar or not.It works, but the content is still clipped and not fully visible. Do you know why?

Here’s the updated version based on your help
Ah, I found that this version works as expected. I moved
overflow-hidden
to the inner <div>
and removed sticky
from the <Header />
. Not sure exactly why it works, but if you have any feedback, I’d really appreciate it!