When the screen size is smaller, the rest of the side bar content is invisible (like overflow: hidden) in my project. But it in example it is scrollable, even though it is scrollable it is stretching 1.cms-element, if I make align-items: flex-start;
it is only affecting 1.cms-element and making huge gap between 3.cms-element.
If I give overflow-y: scroll; max-height: 100vh;'
to .side
class it is effecting sidebar height and style. If I give min-height: 100vh;
to .side
class it working but stretching another elements to fit in the content.
How can I achieve this without effecting another elements ? Also order should not change as given 1, 2, 3, 4.
How can I make sidebar visible in all sizes without effecting other elements size
2
Answers
One solution could be to wrap the content inside the sidebar in a container with a fixed height and overflow-y: scroll; This way, the container will be scrollable while not affecting the rest of the page elements.
HTML:
CSS:
To make the sidebar fit in all screen sizes, it is necessary to adjust the gap of each element with respect to the sidebar height (
calc(100vh - ([no. of .cms-element] * 2rem)
), as therow-gap
value can interfere with the sidebar height.Also by using
grid-row: ([total no. of .cms-element]+1)/-2
in the.side
element, it is possible to preserve the gap between the 1.cms-element and 3.cms-element.JavaScript can be utilized for a more flexible approach to maintaining the value mentioned above.
Here is the solution based on your example:
SCSS:
Javascript:
Hope you find it useful 🙂