I have a nogap.html like this:
.iblock {
display: inline-block;
width: 200px;
height: 50px;
border: 1px solid blue;
}
.fblock {
display: block;
width: 200px;
height: 50px;
border: 1px solid red;
}
<div class="iblock">AA</div><div class="iblock">BB</div>
<div class="fblock"></div>
and it displays well like this(Chrome 76):
But if I remove the text AA and BB from html source file above, there arises a gap between the two lines of boxes, like below. Why? And How to remove that weird gap?
=============
Well, I got it, this is due to default value vertical-align: baseline
on all <div
>s. Injecting a letter 'q' reveals this.
I deduce that:
- When a inline-block DIV has no text, that DIV's bottom border is considered the baseline, so the problem arises.
- But if a inline-block DIV has some text, those text's baseline is considered as baseline, so I see the difference.