Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
861 views
in Technique[技术] by (71.8m points)

这种APP底部横线+文字该怎么布局?css

image.png

如图所示

下面是我做的,但是宽度不好控制,设备宽度不一样显示也不一样,有好的解决方案嘛
image.png

<div class="state flex flex-y flex-x">
    <span class="line"></span>
    <p>用户须知</p>
    <span class="line"></span>
</div>
.state{
    color: #666;
    font-size: 14px;
}
.line{
    width: 35%;    
    height: 1px;
    background-color: #dedede;
}```

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<!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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...