The markup is like:-
<div id="parent">
<div class="top">
<ul>
<li>...
</ul>
</div>
<div class="bottom">
<ul>
<li>Option A
<li>Option B
<li>Option C
</ul>
</div>
</div>
And the CSS is:-
div {
border: 1px solid black;
}
#parent {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
.top {
max-height: 200px;
overflow: scroll;
}
So, basically what I want is that bottom
div
should touch the lower edge of the window and the rest space should be taken by top
div
. My current approach of setting max-height
in top
div
is clearly not good since based on screen size (on mobiles) it will be either too less or big. Can I achieve this using CSS only?
Here is a jsfiddle for this - http://jsfiddle.net/Ldr07h2r/
This is pretty straightforward with Flexbox layout. In this case you don't have to specify an explicit height
for the bottom <div>
, the top one would take the remaining space:
EXAMPLE HERE
#parent {
/* other declarations... */
display: flex;
min-height: 100vh;
flex-direction: column;
}
.top {
overflow: auto; /* Up to you! */
flex: 1;
}
Have a look on these properties:
flex
flex-direction
You have to position div.bottom absolute and set div.top height 100% - div.bottom.
Your final css has to be:
div {
border: 1px solid black;
}
#parent {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
.top {
height: calc(100% - 100px);
overflow: scroll;
}
.bottom {
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
}
Here is the updated fiddle: http://jsfiddle.net/Ldr07h2r/4/
Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With