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>效果图:

更多编程相关知识,请访问:编程教学!!










