css 居中

        /* 绝对定位元素居中:  */
        .loading-img {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        /* 一般块儿级元素居中:  */
        .div_container {
            width: 500px;
            margin: 0 auto;
        }

        /* 块儿级元素内部元素居中(flax布局,水平居中为例):  */
        li {
            width: 100px;
            height: 100px;
            display: inline-block;
            border: 10px solid red;
            margin: 20px;
        }

        ul {
            width: 100%;
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            justify-content: center;
            padding-start: 0;
            /*默认padding-start有40px*/
        }

        /* left:0; right:0; top:0; bottom:0; margin:auto;会使child居中,如果child没有宽高,则会继承父集的宽高,适合body 内的遮罩 */
        .child {
            width: 50px;
            height: 50px;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }

 

posted @ 2017-12-22 14:14  我将枕中记忆抹去任岁月浮光掠影  阅读(244)  评论(0编辑  收藏  举报