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>
        激情五月色婷婷 | 超碰成人福利 | 成人无码免费视频 | 一区二区三区福利视频 | 4438成人在线 | 日本苍井空特黄A片 | 亚洲无码第一页 | 成人性爱视频网址导航 | 欧美强奸视频 | 中文字幕第九页 |