<div style="background:red;font-size:12px;line-height:50px;">首先,不固定高度line-height也可以实现文字垂直居中</div>
<div style="background:green;font-size:12px;line-height:30px;">当高度自适应时,文字的顶端和文字的底端的距离会随line-height大小变化而变化,但实际上文字还是垂直居中的(不考虑padding)</div>
<div style="background:blue;font-size:12px;line-height:25px;height:25px">由于可能为了布局需要,要固定高度,为了实现单行文字垂直居中,从而设置line-height的值与height值设置一致</div>
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/dc54564e9258d1098870f509d058ccbf6d814dfd?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)