阅读背景:

元素居中方式总结

来源:互联网 

垂直居中:

块级元素

1.使用position设置定位方式后进行元素的偏移

    .box {
      width: 300px;
      height: 300px;
      background-color: burlywood;
      position: relative;
      top: 50%; /*元素顶部将会定位到希望的居中位置,需要将元素上移自身高度的50%*/
      margin-top: -150px;
      /*上移自身高度的一半*/
      /*
      transform: translateY(-50%);
      CSS3特性,可在高度不确定时使用
      */
    }  
    



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: