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 div
s. 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.a
is a normal div. There is no styling ofline-height
orfont-size
here.div.b
only stylesh1
to haveline-height: 1.2
.div.c
only stylesspan
to havefont-size: small
.div.d
styles bothh1
to haveline-height: 1.2
andspan
to havefont-size: small
.
Why does the heading in div.d
have a larger height than the others?