常见的居中方式

2017-08-12  本文已影响0人  size_of

适用于固定宽高:

.center1{
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;
            width:100px;
            height:100px;
        }
.center2{
            position: fixed;
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;
            width:100px;
            height:100px;
        }

适用于固定宽高和非固定宽高:

.center3{ 
            position:absolute; 
            width:140px; 
            height:140px; 
            top:0;
            right:0;
            bottom:0; 
            left:0; 
            margin:auto;
      }
.center4 {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            -webkit-transform: translate(-50%, -50%);
            -moz-transform: translate(-50%, -50%);
            -ms-transform: translate(-50%, -50%);
        }
.center5{ 
            position:fixed; 
            width:140px; 
            height:140px; 
            top:0;
            right:0;
            bottom:0; 
            left:0; 
            margin:auto;
      }
.center6 {
            display: table-cell;
            vertical-align: middle;
            text-align: center;
        }
.outbox::before{
                content:"";
                width:0;
                height:100%;
                display:inline-block;
                vertical-align:middle;
            }
            .outbox{
                position:fixed;
                top:0;
                right:0;
                bottom:0;
                left:0;
                text-align:center;
            }
            .content{
                width:200px;
                height:200px;
                background-color:#ccc;
                display:inline-block;
                vertical-align:middle;
            }
上一篇下一篇

猜你喜欢

热点阅读