I have 2 elements inside .container, that is .header and .overflowElem.
I want .overflowElem to take the remaining height of the .container, and it should be overflow-y: auto.
HTML
<div class="box">
<div class="container">
<div class="header">
<h1>HEADER</h1>
</div>
<div class="overflowElem">
<ul>
<li><a href="#">ITEM 1</a></li>
<li><a href="#">ITEM 2</a></li>
<li><a href="#">ITEM 3</a></li>
</ul>
</div>
</div>
</div>
All of this HTML is injected using jQuery's ajax, like so:
$.ajax({
type: "GET",
url: "include/get_list.php",
data: params
}).done(function(data) {
var container = $("<div></div>")
.attr("class", "container")
.html(data)
.hide()
.appendTo(box);
}).fail(function() {
alert("Error.");
}).always(function(data) {
})
Notice how var container is hidden at the time of initialization
CSS :
div.box {
width: 700px;
border: 1px solid red;
padding: 45px 20px 20px;
}
div.container {
height: 500px;
background-color: #bbb;
}
div.header {
background-color: red;
/* HEIGHT in pixels is UNKNOWN */
}
div.overflowElem {
overflow-y: auto;
/*
CANNOT USE THIS BECAUSE i DON'T know the height of .header
height: calc(100% - height of .header in pixels);*/
}
jsfiddle:
https://jsfiddle.net/n4z02gL2/1/
Now, i could add a height to .header and calculate the height of .overflowElem using calc() and bingo!
BUT, because all of the HTML is inserted using jQuery's ajax, and it's hidden at the moment of initialization, i don't tknowthe height neither i cant get it using ajax because the container is hidden
So, what is the solution? Any ideas, tips, tricks, hacks... Thanks