如何实现文字两边中划线的效果?
为了在文字的两边添加红框中所示的中划线,可以利用 css 中的 ::before 和 ::after 伪元素。
步骤:
)设置为 flex 布局,文本居中对齐。
代码示例:
立即学习“前端免费学习笔记(深入)”;
<!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号