I have 3 divs 1 x 100%
and 2 x 100vw
.
Then if I set 100vh height to 100vw div (the black one) - I will get overflow-x and will get horizontal scroll.
Why is this happening? As per my understanding in this case 100vw
should be equal to 100%
as they're inside the body
which doesn't have any margin/padding and has box-sizing: border-box
.
show100vhDiv = function() {
document.querySelector('.height-100vh').classList.toggle('hidden');
}
@import url('https://fonts.googleapis.com/css?family=Lato&display=swap');
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Lato;
padding-top: 30px;
}
.test {
height: 30px;
margin: 20px 0;
display: flex;
justify-content: center;
align-items: center;
color: white;
text-transform: uppercase;
letter-spacing: 20px;
}
.width-100vw {
background: salmon;
width: 100vw;
overflow: hidden;
}
.height-100vh {
background: black;
height: 100vh;
color: white;
}
.width-100 {
width: 100%;
background: mediumvioletred;
}
.hidden {
display: none;
}
button {
position: relative;
left: 50%;
transform: translateX(-50%);
}
<button onclick="show100vhDiv()">Toggle 100vh x 100vw element</button>
<div class="test width-100vw">100vw</div>
<div class="test width-100">100%</div>
<div class="test width-100vw height-100vh">100vh x 100vw</div>