You can use the style height: 100vh;
, which gives the element the total height of the viewport (visible window area):
Example:
body{
margin: 0;
}
#primeira{
background-color: yellow;
height: 100vh;
}
<div id="primeira">
Primeira div
</div>
<div>
Segunda div
</div>
<div>
Terceira div
</div>
Using height: 100%
So that the div
be the same height as viewport using percentage (%
), it is necessary to define the html
and the body
in 100%
.
html, body{
margin: 0;
height: 100%;
}
#primeira{
background-color: yellow;
height: 100%;
}
<div id="primeira">
Primeira div
</div>
<div>
Segunda div
</div>
<div>
Terceira div
</div>
Using Javascript
You can use the window.innerHeight
to catch the height of viewport and assign to the height
of the first div
. Example:
var el = document.body.querySelector("#primeira");
function altura(){
el.style.height = window.innerHeight+"px";
}
document.addEventListener("DOMContentLoaded", altura);
window.addEventListener("resize", altura);
body{
margin: 0;
}
#primeira{
background-color: yellow;
}
<div id="primeira">
Primeira div
</div>
<div>
Segunda div
</div>
<div>
Terceira div
</div>
In jQuery would be:
$(window).on("load resize", function(){
$("#primeira").css("height",window.innerHeight+"px");
});
body{
margin: 0;
}
#primeira{
background-color: yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="primeira">
Primeira div
</div>
<div>
Segunda div
</div>
<div>
Terceira div
</div>
do not want a menu, yes all div occupy the display
– maiquel
The best way to do this is by using css itself
– Yago Azedias