如题,元素内有文字,元素设置了高度和行高相等,却没有垂直居中?请问是啥子情况?
如下图:
css设置是这样的:
.Mail_list .list_block .bottom dd{
float: right;
width: 26%;
height: 20px;
line-height: 20px;
text-align: center;
border: 1px solid #ff6c00;
color: #ff6c00;
border-radius: 3px;
-webkit-border-radius: 3px;
font-size: 14px;
margin-right: 5%;
}
应该是你设置了该
dd
的box-sizing: border-box
导致的,因为当你修改默认盒模型为border-box
时,你设置的height
就默认包含了内容高度
和边框高度
(2px), 所以这里你设置height:20px
, 那么你的内容高度就只剩18px
了,所以你再设置line-height:20px
是超出内容高度的,如果想要垂直居中,有3种方法: