纯CSS实现中间文字 两端横线的方法.
效果演示
代码演示
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>line</title>
<style>
/*第一种方法*/
fieldset {
border: none;
padding: 0;
border-top: 1px blue solid;
text-align: center;
width: 300px;
margin: auto;
}
legend {
padding: 0 10px;
font-size: 16px;
color: blue;
}
/*第二种方法*/
.title {
color: red;
text-align: center;
font-size: 16px;
}
.title:before,
.title:after {
content: "";
width: 100px;
border-top: 1px red solid;
display: inline-block;
vertical-align: middle;
}
.title:before {
margin-right: 10px;
}
.title:after {
margin-left: 10px;
}
h3 {
font-size: 16px;
font-weight: bold;
color: #000;
text-align: center;
width: 100%;
margin-bottom: 20px;
display: flex;
flex-direction: row;
}
h3:before,
h3:after {
content: "";
border-bottom: 1px solid #000;
margin: auto;
width: 100px;
}
h3:before {
margin-right: 10px;
}
h3:after {
margin-left: 10px;
}
</style>
</head>
<body bgcolor="#F2F2F2">
<!--第一种方法-->
<fieldset>
<legend><span>第一种方法</span></legend>
</fieldset>
<!--第二种方法-->
<div class="title">第二种方法</div>
<!--第三种方法-->
<h3>
第三种方法
</h3>
</body>
</html>