I have a page with stacked divs and the divs are added dynamically in a block fashion. It has to cover 100% of viewport height and show scrollbar when content goes beyond viewport. The issue I am facing is outer-div has to have a background-color. When given a min-height of 100% to this div and applying height:1px fix so that child div inherits 100% height, I get the desired effect as in child inside parent with min-height 100% not inheriting height However, the background color doesn't extend to full height. The nested divs and the mechanism to add divs dynamically is mimicked here: https://jsfiddle.net/b859L1gs/
$(document).ready(function() {
$("#clickme").click(function() {
$(".two").append(" < div class = 'region' > < /div>")
});
})
html {
height: 100%;
}
body {
height: 100%;
}
.one {
min-height: 100%;
height: 1px;
background: green;
}
.two {
height: 100%;
}
.region {
height: 200px;
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>
<div class="one">
<div class="two">
<div class="three">
...
<div class="region">
</div>
<button id="clickme">
here
</button>
</div>
</div>
</div>
</body>
</html>
Click the button to expand the divs and see the height expand but not the background-color. Note that the constraint as per application is to but background-color only at first outermost div and not to body.