1

I just tried using css display: inline-block in my code to create 3 side by side columns. I set the margin and padding to 0, but the edges of the columns are not touching (I bordered the elements to visualize the effect); its like there is some default margin given to display: inline-block.
How can one align the edges of display: inline-block elements without using guess values of -ve margin or absolute positioning.

<div>
  <div style='display: inline-block;'>apple</div>
  <div style='display: inline-block;'>ball</div>
  <div style='display: inline-block;'>cat</div>
</div>
Chisom.joe
  • 85
  • 5

1 Answers1

0

The solution is to add font-size: 0 to the parent element, and then declare your default font-size on the children.

ul {
    font-size: 0;
}
li { 
    display: inline-block;
    width: 100px;
    font-size: 15px;
}

li:nth-child(1) {
    background: #f33;
}
li:nth-child(2) {
    background: #3f3;
}
li:nth-child(3) {
    background: #33f;
}
    <ul>
        <li>element 1</li>
        <li>element 2</li>
        <li>element 3</li>
    </ul>
sandes
  • 1,190
  • 11
  • 22