This spacing occurs because elements with inline-block
causes line break spaces or normal spaces to affect rendering, since this is the expected effect of properties that use inline
(as inline-block
and inline-table
)
To correct you can use float:;
and clear
with a "pseudo element" ( ::after
):
.itens {
list-style-type: none;
padding: 0;
margin: 0;
}
.itens > li {
float: left;
padding: 20px;
background: red;
}
.itens::after {
clear:both;
content: "";
display: block;
}
<ul class="itens">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Or set font-size
to 0
in ul
:
.itens {
font-size: 0;
list-style-type: none;
padding: 0;
margin: 0;
}
.itens > li {
display: inline-block;
padding: 20px;
background: red;
font-size: 11pt;
}
<ul class="itens">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
To see how the line breaks affect it, remove any space between the LIs:
.itens {
list-style-type: none;
padding: 0;
margin: 0;
}
.itens > li {
display: inline-block;
padding: 20px;
background: red;
font-size: 11pt;
}
<ul class="itens">
<li>Item 1</li><li>Item 2</li><li>Item 3</li>
</ul>