I want to make a div that is always the height of the screen, even if it has more content in it. The div shows a list of , and if there are more than can be contained in the screen there will be a scrollbar on the side of the div.
<div class = "Row">
<div class ="col-sm-2">
<ul>
<li>
<h1>record1</h1>
</li>
<li>
<h1>record2</h1>
</li>
</ul>
</div>
</div>
I've searched online but only found answers that have nothing to do with my issue, like scrollable modals and other scroll issues. Please explain your answer fully with steps and full code.
-
Maybe you've searched online using the wrong keywords?Khalid T.– Khalid T.2016年02月17日 13:43:05 +00:00Commented Feb 17, 2016 at 13:43
-
I specifically added that last line because people answer in one word, assuming that I know what they mean.MJH– MJH2016年02月17日 13:43:22 +00:00Commented Feb 17, 2016 at 13:43
-
@Then I don't know the right keywords. I've tried every combonation I could think of and didn't find anything.MJH– MJH2016年02月17日 13:44:24 +00:00Commented Feb 17, 2016 at 13:44
-
@rosa you could have taken a look here: link and then here link very basic search keywords on stackoverflowPeter– Peter2016年02月17日 13:47:32 +00:00Commented Feb 17, 2016 at 13:47
-
1Working example using vh and % : jsfiddle.net/Laa87pkwJay– Jay2016年02月17日 14:14:24 +00:00Commented Feb 17, 2016 at 14:14
1 Answer 1
A web page's body is by default only as high as the content one put into it, so we need to tell it to be full viewport height (the size of the browser window)
html, body {
margin: 0;
height: 100%;
}
Now, for your row div to also be full height, we give that to a height
.row {
height: 100%;
}
And finally, for the scroll bar to appear when the content exceed the height, we add
.row {
overflow: auto;
}
The background: #eee; I just added so you see that covers the whole browser window
The height: 100% will now make the row div to automatically fill up the entire viewport (browser window) no matter size or if one resize it.
Sample code snippet
html, body {
margin: 0;
height: 100%;
}
.row {
height: 100%;
background: #eee;
overflow: auto;
}
<div class = "row">
<div class ="col-sm-2">
<ul>
<li>
<h1>record1</h1>
</li>
<li>
<h1>record2</h1>
</li>
<li>
<h1>record3</h1>
</li>
<li>
<h1>record4</h1>
</li>
<li>
<h1>record5</h1>
</li>
<li>
<h1>record6</h1>
</li>
</ul>
</div>
</div>
Explore related questions
See similar questions with these tags.