CSS小技巧--文字对齐

214 阅读1分钟

要实现这样的效果:(用空格也太low的吧)

核心就是 text-align: justify;

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    div{
  border: 1px solid red;
  font-size: 20px;
}
span{
  border: 1px solid green;
  display: inline-block;
  width: 5em;
  text-align: justify;
  line-height: 20px;
  overflow: hidden;
  height:20px;
}

span::after{
  content: '';
  display: inline-block;
  width: 100%;
  border: 1px solid red
}
  </style>
</head>
<body>
<div>
  <span>姓名</span>
  <br>
  <span>联系方式</span>
</div>
</body>
</html>