4 个回答

试试下面这个,看看是不是你想要的

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .title{
      text-align: center;
      overflow: hidden;
    }
    .title span{
      position: relative;
      display: inline-block;
    }
    .title span::before{
      content: '';
      position: absolute;
      top: 50%;
      width: 1000px;
      height: 1px;
      left: 100%;
      background-color: #333;
    }
    .title span::after{
      content: '';
      position: absolute;
      top: 50%;
      right: 100%;
      width: 1000px;
      height: 1px;
      background-color: #333;
    }
  </style>
</head>
<body>
  <div class="title"><span>测试文字</span></div>
</body>
</html>

除了上面的方法,还有个自己以前琢磨出来的办法。

<div class="text-box">
  <span class="text">文字文字</span>
</div>
<style>
.text-box {
    display:table;
    width:100%;
}
.text {
    display:table-cell;
    width: 90px;
    text-align: center;
    position:relative;
    bottom:-4px;
}
.text-box::before,.text-box::after {
    content:"";
    display:table-cell;
    border-bottom:#ccc solid 1px;
}
</style>

https://jsfiddle.net/67n5dcod/1/

直接上代码:
html部分:

        <div class="bottom-line"></div>
        <div class="time"></div>

css部分:

.bottom-line{
  position: relative;
  width: 27.6rem;
  height: 1px;
  background-color: #E6E6E6;
  margin: 3rem auto 0
}
.time{
  position: relative;
  color: #999999;
  width: 10rem;
  margin: -0.5rem auto 0;
  z-index: 5;
  text-align: center;
  background-color: #fff;
}
推荐问题