I have a question regarding overflow-y:auto and pop up. I have 2 divs inside a pop up but only on the second one I want to implement some scrolling if needed. The pop up has a max-height so if the second div has a bigger height than the max height of the pop up I would expect to see a scroll. But in fact that is not what happens. The second div just increases to a higher height than the pop up extending to a place out of the pop up. Why does this happen?
This is how it looks like:
The css:
.class1 {
max-height: 100px;
}
.class2 {
height: 300px;
overflow-y: auto;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
The HTML:
2
Answers
If you want to make the
class2
scroll insideclass1
, you need to add this css insideclass1
(the popup container):Full Code:
For more info visit: overflow – css tricks
class1
is the parent class forclass2
. You set a max height to the parent class,class 1
.Class2
has a height of300px
, which is more significant than the parent classclass1
. So basically the child class is already bigger than the parent classclass1
. When you enter content in the child class that isclass2
it grows more than the height of the parent class that isclass1
. Now the solution code is: