You should look to use vh
and vw
units, rather than %
in this case.
The viewport-percentage lengths are relative to the size of the
initial containing block. When the height or width of the initial
containing block is changed, they are scaled accordingly. However,
when the value of ‘overflow’ on the root element is ‘auto’, any scroll
bars are assumed not to exist. Note that the initial containing
block's size is affected by the presence of scrollbars on the
viewport. ~ w3.org
For example,
html,
body {
margin: 0;
padding: 0;
font-size: 0;
}
.item {
height: 50vh;
white-space: 0;
width: 32vw;
margin: 0;
background: tomato;
display: inline-block;
font-size: initial;
transition: all 0.6s;
}
.item:hover {
background: cornflowerblue;
}
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
will always fill the screen size, no matter what size it is.
You may note that I have set font-size to 0, and then 'initial' in my .item
class. This is to 'fix' the margin that is generated via inline block elements.
you also need to ensure there is no whitespace between your elements, as they will be taken as an actual space in your html.