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
Post a Comment