css - 单行文本与多行文本垂直居中?
本文介绍了css - 单行文本与多行文本垂直居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
手机端三个块的高度一样,并且文本垂直居中
我试过用line-height、position都不行
尽量用css,兼容ie8、9
解决方案
我觉得最稳的还是table
<style>
* {
padding: 0;
margin: 0;
}
html, body {
width: 100%;
height: 100%;
}
.box {
width: 100%;
height: 200px;
background-color: #ec5151;
}
.box > div {
display: table;
width: 100%;
height: 100%;
}
.box > div > span {
display: table-cell;
vertical-align: middle;
text-align: center;
}
</style>
<body>
<div class="box">
<div>
<span>3306</span>
</div>
</div>
</body>
预览如图片所示
这篇关于css - 单行文本与多行文本垂直居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文