how to make sidebar scroll-able.
hey, this is something i've been stumped on for a while. How would i make the sidebar on the left scrollable on the vertical axis, but not the "page" or content on the right? So the content on the right sticks whilst you're able to scroll through the would be nav. I'd appreciate any insight, thanks in advance.
https://codepen.io/deerCabin/pen/QWXRage
8 Replies
Add height and overflow-y to your box-1 element
You can check your codepen
And you can adjust the height as per your requirements.
That works, but I feel since you have to set a fixed height, you’ll end up having to adjust it depending on your use case which doesn’t help it be dynamic, unless that is the only way?
What do you mean by dynamic here ??
@snxxwyy
Do you plan on changing the height of your sidenav ??
You can use a container and set the the height to be 100ch.
Wrap the side columns in its own container.
Give this container the property
container-type: size;
Then give your box-1 these styles:
the result i got from that is exactly what i meant. Thanks chris. With the way that works, is that because
container-type: size;
is saying the container size is the exact way it is in the viewport and then the styles on box-1 works out how you're viewing the content? If not, could you please explain why it's working the way it is?though i've noticed that when you shrink the window and the
box-2
content shrinks down, you can't scroll to access it?yes, the issue here is that the 100cqb is giving it the height of its parent container which, as this is a grid, is based on the height of the main content block as it gets taller as the viewport gets narrower.
I have only recently started looking at containers and container units so maybe there is something better. 🤔
Maybe you could set a max-height based on the viewport height on the .box-1 parent element.
So you might have something like this:
Ah I see, no worries. I’ll give that a shot and experiment with it, thank you.