
实现文字两边中间横线的 css 样式
问题:
如何使用 css 实现<p>标签内文字两边中间带有横线的样式?
解决方案:
使用 ::before 和 ::after 伪元素,以及 flex 布局和 content 属性。
代码示例:
立即学习“前端免费学习笔记(深入)”;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.text {
display: flex;
align-items: center;
justify-content: center;
}
.text::before {
content: "";
flex: 1;
background-color: red;
height: 1px;
margin-right: 10px;
}
.text::after {
content: "";
flex: 1;
background-color: red;
height: 1px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="text">一段文字</div>
</body>
</html>在这个示例中:
以上就是如何使用 CSS 实现 `` 标签内文字两边中间带有横线的样式?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号