1. <span id="z4nqb"></span>
      ????????? DIV內部子元素層水平垂直居中方法與CSS代碼 ?????????

      如果父元素層DIV沒有設置寬度與高度,如何讓子層里面的DIV相對父層水平垂直居中?是HTML+CSS前端開發(fā)人員經(jīng)常遇到的難題,下面易網(wǎng)技術小編分析以下三種方法,可供參考!

      DIV內部子元素層水平垂直居中

      一、父元素層DIV沒有絕對定位屬性(兼容IE8+):

      <style type="text/css">
      .parent {
      width: 800px;
      height: 500px;
      background: #333;
      display: table-cell;
      vertical-align: middle;
      text-align: center;
      }
      .child {
      display: inline-block; /*可選,讓child寬度自適應文字寬度*/
      padding: 10px;
      background-color: red;
      }
      </style>
      
      <div class="parent">
        <div class="child">ABCDEFG</div>
      </div>

      二、父元素層DIV有絕對定位屬性(兼容IE8+):

      <style type="text/css">
      .parent {
      position:absolute;
      width: 800px;
      height: 500px;
      background: #333;
      display: table;
      text-align: center;
      }
      .child {
      display: table-cell;
      vertical-align: middle;
      }
      .child-child {
      display: inline-block; /*可選,讓child-child寬度自適應文字寬度*/
      padding: 10px;
      background-color: red;
      }
      </style>
      
      <div class="parent">
        <div class="child"><div class="child-child">ABCDEFG</div></div>
      </div>

      三、子元素層DIV絕對定位法(推薦,兼容IE10+)

      下面這種方法是易網(wǎng)技術小編推薦的。因為隨著新版WIN10自帶瀏覽器也用上了Chromium內核,不難想象,以后的前端開發(fā)工作,瀏覽器的兼容性測試可能成為歷史。

      這種方案只要給子元素層DIV加上以下CSS屬性即可:

      .child {position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);}

      1. <span id="z4nqb"></span>
        手机看片在线播放联合毛片 | 超碰大鸡巴 | 91 日韩 国产 | 综合亚洲在线 | 丁香花高清在线完整版 | 色av婷婷 | 亚洲国产成人精品女人久久久 | 日韩色情影视 | 国产8x8x| 日韩中AV无码毛片 |