Here is my code:
div {
border: thin solid gray;
display: inline-block;
}
h1 {
background: lightblue;
}
span {
background: orange;
}
.b h1 {
line-height: 1.2em;
}
.c span {
font-size: 0.5em;
}
.d h1 {
line-height: 1.2em;
}
.d span {
font-size: 0.5em;
}
<div class="a"><h1>Foo<span>Bar</span></h2></div>
<div class="b"><h1>Foo<span>Bar</span></h2></div>
<div class="c"><h1>Foo<span>Bar</span></h2></div>
<div class="d"><h1>Foo<span>Bar</span></h2></div>
There are four divs. Each div has an h1 and a span nested in h1. Only the line-height and font-size styles are relevant for this question. The other styles are just for visualising the issue. Here is what to focus on,
div.ais a normal div. There is no styling ofline-heightorfont-sizehere.div.bonly stylesh1to haveline-height: 1.2.div.conly stylesspanto havefont-size: small.div.dstyles bothh1to haveline-height: 1.2andspanto havefont-size: small.
Why does the heading in div.d have a larger height than the others?