李艳军

 

多行文字居中

 

对于多行文字的居中,用一句话概括就是:把包裹在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

posted on 2017-03-18 00:21  李艳军  阅读(127)  评论(0编辑  收藏  举报

导航