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中文网其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。