Reputation: 43
I want to add scroll on bottom child div when its overflowing the parent. I don't want to set any height for both top and bottom div. it has to calculate the remaining height from parent and its should show the scroll only in bottom div
#parent{
height:100px;
width:100px;
border: 1px solid red;
}
#top{
background-color: #CCC;
width:100%;
height:auto
}
#bottom{
height: auto;
width: 100%;
background-color: grey;
overflow-y:auto;
}
<div id="parent">
<div id="top">
top content
no need of scroll
</div>
<div id="bottom">
I need scroll here when
this content overflow the parent.
</div>
</div>
Upvotes: 4
Views: 2247
Reputation: 14173
You can achieve this using flexbox:
display: flex;
to #parent
flex-direction: column;
to #parent
to set the directionflex: 1;
to #bottom
for it to take up the desired space#parent{
height:100px;
width:100px;
border: 1px solid red;
display: flex;
flex-direction: column;
}
#top{
background-color: #CCC;
width:100%;
height:auto
}
#bottom{
height: auto;
width: 100%;
background-color: grey;
overflow-y:auto;
flex: 1;
}
<div id="parent">
<div id="top">
top content
no need of scroll
</div>
<div id="bottom">
I need scroll here when
this content overflow the parent.
</div>
</div>
Upvotes: 4