CSS提供了在网页中间制作包含文字或图像的水平线以使其具有吸引力的功能,这可以通过使用简单的CSS属性来实现。
语法:
h4:before, h4:after { content: ""; flex: 1 1; border-bottom: 2px solid #000; margin: auto; }
示例1:将文字显示在水平线中间
<!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>HTML中文网</h4> </body> </html>
效果图:
示例2:将图像显示在水平线中间
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> h1 { display: flex; flex-direction: row; } h1:before, h1:after { content: ""; flex: 1 1; border-bottom: 2px solid #000; margin: auto; } img { height: 100px; width: 120px; border-radius: 50%; } </style> </head> <body> <h1> <img src="https://www.0133.cn/static/images/logo.png-600"> </h1> </body> </html>
效果图:
以上就是如何使用CSS将文字显示在水平线中间?的详细内容,更多请关注0133技术站其它相关文章!