问题描述:
使用line-height设置文本垂直居中不生效。
// html代码
<div class="box">让我居中</div>
// css代码
.box{
width: 300px;
height: 200px;
line-height: 200px;
font: 14px PingFangSC-Semibold;
background: #999;
}

原因分析:
font 属性覆盖了line-height属性,所以line-height不生效。
解决方案:
- font属性提取到line-height属性之前。
- 不使用font属性,分别设置字体相关样式。
// html代码
<div class="box">让我居中</div>
// css代码
.box{
width: 300px;
height: 200px;
font: 14px PingFangSC-Semibold;
line-height: 200px;
background: #999;
}

487

被折叠的 条评论
为什么被折叠?



