<!DOCTYPE html>
<html>
<head>
<title>HTML 文字居中示例</title>
<style>
/* 使用 CSS 居中文字 */
.center-text {
text-align: center; /* 水平居中 */
height: 100vh; /* 设置高度为视口高度 */
display: flex; /* 使用 Flexbox 布局 */
align-items: center; /* 垂直居中 */
justify-content: center; /* 水平居中 */
}
</style>
</head>
<body>
<div class="center-text">
这里是居中的文字
</div>
</body>
</html>
text-align: center;
:使文本在水平方向上居中。height: 100vh;
:设置容器的高度为视口高度,确保垂直居中有足够的空间。display: flex;
:使用 Flexbox 布局,方便进行垂直和水平居中。align-items: center;
和 justify-content: center;
:分别用于垂直和水平居中内容。上一篇:html5qrcode
下一篇:html下拉列表
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站