html - line-height doesn't vertically center inline-block -


i tried vertically center inline-block this:

div {    width: 50px;    height: 50px;    background: red;    line-height: 50px;  }  span {    display: inline-block;    width: 20px;    height: 20px;    background: white;  }
<div>    <span></span>  </div>

but span not vertically centered. why?

because line-height sets position of baseline of text (the bottom end of span). since span 20px high must add half of line-height:

div {    width: 50px;    height: 50px;    background: red;    line-height: 60px;  }  span {    display: inline-block;    width: 20px;    height: 20px;    background: white;  }
<div>    <span></span>  </div>


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -