css居中

转自:How to Center Anything With CSS 

http://designshack.net/articles/css/how-to-center-anything-with-css

盘点8种CSS实现垂直居中水平居中的绝对定位居中技术

http://blog.csdn.net/freshlover/article/details/11579669

div.showBox
        {
            position: fixed;//①
            z-index: 999; //②
            padding: 0px; 
          
           
            border: 4px solid rgba(0,0,0,0.1);
            border-radius: 5px;            
            
           
           
            margin: 0 auto; //③
            margin-top: 34.5px;            
             696px; //④
            height: 441px;
             
           left:0px;right:0px;//⑤
            
        }

 注:指定宽度和margin:0 auto就可以居中了。

但是本文要实现的是类似于弹框的水平居中,所以追加了z-index,z-index生效需要追加position。

到此,预览。。。。我去,水平居中失败。。。。原因嘛,不知道,蛋疼了啊。。。

然后各种百度。。。然后追加 上⑤就能居中了。。。原因不明,我去

原文地址:https://www.cnblogs.com/ribavnu/p/4527504.html