Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

html - When I increase the line-height of inline-block or block-level element, why does the text inside remains centered in the middle?

span {
    display:inline-block;
    background-color: red;
    line-height:100px;
    vertical-align: ;
}
  <span>Testing</span>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's because increasing the line-height of an inline-block increases the 'strut' of its line-box, which increases the height of the line-box equally on both sides, top and bottom, which results in the anonymous inline-box holding the text inside the line-box to remain centered in the middle, as the baseline is pushed down.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...