I've run into an interesting problem with line-height
.
.text {
font-family: sans-serif;
font-size: 11px;
line-height: 12px;
}
.container {
display: flex;
}
<div class="container">
<div class="text-container"><span class="text">Hello</span></div>
<span class="text">Hello</span>
</div>
In this fiddle above there are 2 spans, both with font-size
and line-height
set, inside a flex container. One of the spans is inside a div
and the other one isn't.
The spans themselves have a height of 12px
, but the div has a height of 18px
, causing the two spans to be out of line. If I add line-height: 0;
to the div, then the problem is fixed and the div is 12px
tall.
The spans must be on the same line, and one of them must be inside a container. display: block
works, but for my purposes this element needs to be inline for certain use cases.
What's causing the div to have this extra height, and is there a nicer solution than having to set line-height: 0;
on the div?