如何使用CSS将文字显示在水平线中间?

如何使用CSS将文字显示在水平线中间?下面本篇文章就来给大家介绍使用CSS实现文字显示在水平线中间效果的方法,希望对大家有所帮助。

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>

效果图:

bc08cfc651327e8c27753d9a32820f6.png-600

示例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>

效果图:

d56c769d5aec89028e938cb9075c106.png-600

以上就是如何使用CSS将文字显示在水平线中间?的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » CSS3 答疑