css中可利用:before、:after和content属性来在文字两边加上横线;语法“E:before,E:after{content:"";flex:1 1;border-bottom:2px solid;}”,E为包含文字的元素。

本教程操作环境:Windows7系统、css3版本、Dell G3电脑。
教程推荐:css视频教程
css在文字两边加上横线的方法
在css中,可以利用:before、:after选择器和content属性来实现。
立即学习“前端免费学习笔记(深入)”;
:before 选择器向选定的元素前插入内容,:after 选择器向选定的元素之后插入内容。
content 属性与 :before 及 :after 伪元素配合使用,来插入生成内容。
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
h4 {
display: flex;
flex-direction: row;
}
h4:before,
h4:after {
content: "";
flex: 1 1;
border-bottom: 2px solid #000;
margin: auto;
}
img {
height: 100px;
width: 100px;
border-radius: 50%;
}
</style>
</head>
<body>
<h4>PHP中文网</h4>
</body>
</html>效果图:

更多编程相关知识,请访问:编程教学!!
以上就是css怎么在文字两边加上横线的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号