I'm trying to get a child div (.form
) with a variable height to use overflow: scroll when its contents expand too much.
The .card
should be dynamic and always be the height of the window, not exceeding it.
The current problem is that when I set the scrolling div to height: 100%, it will exceed it's parent's height and bleed out of it. The (.tab
) at the top is a specific height and not a %. I think this is causing the problem but it must be that specific height.
This entire card needs to be responsive as well to match the window height.
Flex can't be used since it's not supported by IE8.
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
background-color: orange;
}
.card {
position: relative;
background-color: white;
width: 320px;
height: 100%;
margin: 0 auto;
}
.tab, .bottom {
padding: 18px 16px;
text-align: center;
border: 1px solid black;
}
.form {
overflow: scroll;
height: 100%;
}
.form > * > div {
padding: 16px;
}
<div class="card">
<div class="tab">This is a tab</div>
<div class="form">
<div class="form-wrapper">
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div><input type="text"></div>
<div>this and all the input tags above this should be inside .card and a scrollable div (inside the white background)</div>
</div>
</div>
<div class="bottom">This should be inside .card but outside the form. Just below the white background</div>
</div>
Edit: Some clarification
.tab
and .bottom
have fixed heights. The only variable height inside .card
is the overflow: scroll
div.
There will also be another card above this one and it may not work with certain solutions. The two cards have the same width and together, they will take up 100% vh. But I don't think this will be an issue.