<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
.divider {
color: #999;
text-align: center;
}
.divider::before,
.divider::after {
content: '';
display: inline-block;
margin: 0 10px;
width: 100px;
height: 1px;
background: currentColor;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="divider">这是一个分割线</div>
</body>
</html>
上面这个如果考虑移动端宽度问题单位应该用rem,移动端这个应该是共识了。使用flex则可以不考虑宽度问题了,如下面这个:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
.divider {
display: flex;
align-items: center;
color: #999;
text-align: center;
white-space: nowrap;
}
.divider::before,
.divider::after {
content: '';
width: 50%;
height: 1px;
background: currentColor;
}
.text {
padding: 0 1em;
background: #fff;
}
</style>
</head>
<body>
<div class="divider"><span class="text">这是一个分割线sdfdsfssdfs</span></div>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…