0

I want no space between red rectangles, so I checked that all related properties are zero: margin, padding and border. But there is still space. Why? How can I fix it?

 .outer {
    height: 100px;
    width: 600px;
    background-color: grey;
}
.bar {
    background-color: red;
    height: 20px;
    width: 45%;
    display: inline-block;
    margin-top: 20px;
}
<div class="outer">
    <span></span>
    <div class="bar"></div>
    <div class="bar"></div>
</div>
Jofsey
  • 6,821
  • 7
  • 42
  • 64

1 Answers1

2

The space comes from the line break. Either use floating elements or remove the whitespace between the two divs:

 .outer {
    height: 100px;
    width: 600px;
    background-color: grey;
}
.bar {
    background-color: red;
    height: 20px;
    width: 45%;
    display: inline-block;
    margin-top: 20px;
}
<div class="outer">
    <span></span>
    <div class="bar"></div><div class="bar"></div>
</div>
Marvin
  • 7,324
  • 2
  • 22
  • 39