The problem is that items inline-blockare displayed by default with extra space added.
Why? Since the parameter divset to inline-blockhas some built-in characteristics of the element.
A space or line break between elements spanwill result in the space displayed by the browser.
, <p>, , , .
inline-block divs. . , .
:
.ok {
width: 300px;
background: red;
height: 100px;
box-sizing: border-box;
}
.box {
display: inline-block;
box-sizing: border-box;
width: 25%;
border: 2px solid blue;
height: 100%;
}
<div class="ok"><div class="box">1</div><div class="box">2</div><div class="box">3</div><div class="box">4</div></div>
font-size: 0 , , :
.ok {
width: 300px;
background: red;
height: 100px;
box-sizing: border-box;
font-size: 0;
}
.box {
display: inline-block;
box-sizing: border-box;
width: 25%;
border: 2px solid blue;
height: 100%;
font-size: 16px;
}
<div class="ok">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<div class="box">4</div>
</div>
, , , flexbox. . :