多行文字居中

来源:互联网 发布:网络策划 编辑:程序博客网 时间:2024/05/16 12:27

 

对于多行文字的居中,用一句话概括就是:把包裹在inline-block 中的文字 放到 line-height为容器高度的 容器中,代码如下:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style>
  #container{
      width:300px;
      height:300px;
      border:solid 1px grey;
      line-height:300px;
      text-align:center;
  }
  .lineblock{
      display:inline-block;
      line-height:1.4em;
  }
  </style>
</head>
<body>
  <div id="container">
    <div class="lineblock">第一行</br>第二行</div>
  </div>
</body>
</html>

效果如下:

QQ截图20170318002036

0 0