在网页设计中,让文字水平垂直居中是一项常见的需求。CSS提供了多种方式实现这一目标,下面介绍几种方法。1.使用text-align和line-height属性在文字所在的块级元素中,设置text-al
p { width: 200px; height: 200px; text-align: center; line-height: 200px; }
.container { display: flex; justify-content: center; align-items: center; width: 200px; height: 200px; } p { text-align: center; }
.container { position: relative; width: 200px; height: 200px; } p { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
粉丝
0
关注
0
收藏
0