Reputation: 21
how could I make sure that a div takes 100% of the height on every single screen resolution. Like here: https://medium.com/design-playbooks/designing-the-hiring-process-e0b59f3ee53, or here: http://blogs.wsj.com/briefly/2015/01/23/greece-austerity-relief-or-exit-the-short-answer/?mod=e2fb
Upvotes: 1
Views: 4187
Reputation: 6530
If you want to achieve a 100 view height (device height) styling on a div or other elements you can use something like this:
.full-height {
height: 100vh;
}
.full-width {
width: 100vw;
}
div {
background: green;
}
<div class="full-height full-width"></div>
This sets the element size using viewport units, where 1 vh
is 1% of the viewport's height and 1 vw
is 1% of the viewport's width. You can also see an example here: https://dominikangerer.com/projects/github/bearded-cyril/ you can see there that I used this to assign 100vh
to the aside on the left side.
Maybe this is relevant for you: http://caniuse.com/#search=vh
Upvotes: 6
Reputation: 6248
Rather then using 100%
(which will take 100% of the body, but the body may be bigger or smaller then the browser actual visible size), I suggest using the units vh
and vw
100vh
will take 100% of view hight and 100vw
will take 100% of view width. This unit will take 100% of the visible browser screen, no matter what.
CSS:
body{
height:100vh;
width:100vw;
}
Here are some more detailed information about these measurements
Upvotes: 0
Reputation: 8524
You have to style your body to 100% before you can make your div 100%
html, body{
height:100%;
}
div{
height:100%;
}
Upvotes: 0
Reputation: 69042
make your body element 100% hight, then make the div inside 100% hight
Upvotes: 0