I'm struggling to understand the the following css behavior. Maybe I'm missing something important because this actually seems like a simple scenario to me. Consider the following example:
.container {
background-color: lime;
font-size: 20px;
line-height: 20px;
}
<div class="container">
<svg width="1em" height="1em" viewBox="0 0 24 24" >
<circle cx="12" cy="12" r="10"/>
</svg>
Text
</div>
Because container
has line-height: 20px
set, I'd expect it to be 20px high. At least this is the case if it only contains text. With the svg however it is suddenly 24px high, even though the svg is 20px high, as expected because of height=1em
. Also the "Text" has a height of 23px, even though I'd expect it to be 20px.
Interestingly, if I set container
's line-height to something like 30px, it behaves as expected: container
is now 30px
high.
Can you help me understand why container
is not 20px high? Or is line-height
simply not easily predictable once the container contains other elements than just plain text? Thank you!