I have a div element in twitter-bootstrap which will have content that will overflow vertically outside the screen.
I would like the div to take the height of the si
try this
$(document).ready(function(){
$('#content').height($(window).height());
});
Using CSS {height: 100%;}
matches the height of the parent. This could be anything, meaning smaller or bigger than the screen. Using {height: 100vh;}
matches the height of the viewport.
.container {
height: 100vh;
overflow: auto;
}
According to Mozilla's official documents, 1vh is:
Equal to 1% of the height of the viewport's initial containing block.
You need to give height
for the parent element too! Check out this fiddle.
html, body {height: 100%;}
#content, .container-fluid, .span9
{
border: 1px solid #000;
overflow-y:auto;
height:100%;
}
$(document).ready(function(){
$(window).resize(function(){
$(".fullheight").height($(document).height());
});
});
Use simple CSS height: 100%; matches the height of the parent and using height: 100vh matches the height of the viewport.
Use vh instead of %;
This worked for me JsFiddle
Html
..bootstrap
<div class="row">
<div class="col-4 window-full" style="background-color:green">
First Col
</div>
<div class="col-8">
Column-8
</div>
</div>
css
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
JavaScript
var elements = document.getElementsByClassName('window-full');
var windowheight = window.innerHeight + "px";
fullheight(elements);
function fullheight(elements) {
for(let el in elements){
if(elements.hasOwnProperty(el)){
elements[el].style.height = windowheight;
}
}
}
window.onresize = function(event){
fullheight(elements);
}
Checkout JsFiddle link JsFiddle
use
$(document).height()property and set to the div from script and set
overflow=auto
for scrolling