赞
踩
目录
<span>
)内text-align: center;
实例:
.container {
text-align: center;
}
.container span {
display: inline-block;
}
margin: 0 auto;
示例:
.container {
width: 200px;
margin: 0 auto;
}
<span>
)内line-height
等于容器高度示例:
.container {
height: 100px;
line-height: 100px;
text-align: center;
}
.container span {
display: inline-block;
vertical-align: middle;
}
display: flex;
justify-content: center;
和align-items: center;
实例:
.container {
display: flex;
justify-content: center;
align-items: center;
}
position: relative;
position: absolute;
并使用transform
属性进行偏移示例:
.container {
position: relative;
}
.container span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
这些都是常见的文字居中方法,可以根据具体情况选择合适的方式。此外,也可以结合不同的方法来实现更复杂的布局需求。
给博主点赞关注支持一下吧
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。