/* 使用 Flexbox 实现文字上下居中 */
.container {
display: flex;
justify-content: center; /* 水平居中 */
align-items: center; /* 垂直居中 */
height: 100vh; /* 设置容器高度为视口高度 */
}
.text {
/* 文字样式 */
}
.container
是一个容器,使用 display: flex
将其转换为弹性盒子布局。justify-content: center
使子元素在水平方向上居中对齐。align-items: center
使子元素在垂直方向上居中对齐。height: 100vh
设置容器的高度为视口的 100% 高度,确保有足够的空间进行垂直居中。这样,.text
中的文字将会在 .container
容器内实现水平和垂直方向的居中。
上一篇:css 渐变背景
下一篇:css径向渐变
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站