In MDN line-height: <number>
means:
The used value is this unitless
<number>
multiplied by the element's own font size. The computed value is the same as the specified<number>
. In most cases, this is the preferred way to setline-height
and avoid unexpected results due to inheritance.
.parent {
border:1px solid red;
line-height: 4;
font-size: 14px;
}
4 * 14px = 56px
It is equal to the below.
.parent {
border:1px solid red;
line-height: 56px;
font-size: 14px;
}
* {
margin: 0px;
padding: 0px;
}
.parent {
border: 1px solid red;
line-height: 4;
font-size: 14px;
}
.child {
font-size: 30px;
vertical-align: bottom;
border: 1px solid red;
}
.inline-block {
display: inline-block;
vertical-align: bottom;
}
.other {
border: solid 1px green;
}
<span class="parent">char in parent
<span class="child">
<span class="inline-block">display:inline-block</span> char in child
</span>
</span>
<div class="other">other</div>
Let's change line-height:4
into line-height:56px
.
* {
margin: 0px;
padding: 0px;
}
.parent {
border: 1px solid red;
line-height: 56px;
font-size: 14px;
}
.child {
font-size: 30px;
vertical-align: bottom;
border: 1px solid red;
}
.inline-block {
display: inline-block;
vertical-align: bottom;
}
.other {
border: solid 1px green;
}
<span class="parent">char in parent
<span class="child">
<span class="inline-block">display:inline-block</span> char in child
</span>
</span>
<div class="other">other</div>
Why there are different appearances?