css总结

css_居中:table

2018-11-27  本文已影响0人  壮壮成长记

-第一种方法

    <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }
            html,body{
                /* margin:0 auto; */
                height: 100%;
            }

            .parent {
                display: table;
                margin: 0 auto;
                position: absolute;
                top:0;left:0;right:0;bottom: 0;
                margin:auto;
            }

            .parent {
                width: 50%;
                height: 50%;
                background: #808080;
            }

            .child {
                display: table-cell;
            }

            .child {
                vertical-align: middle;
                text-align: center;
            }
            .child>span{
                width:100px;
                height:100px;
                background: #DAA520;
            }
        </style>
    </head>
    <body>
        <div class="parent">
            <div class="child"><span></span></div>
        </div>
    </body>
上一篇 下一篇

猜你喜欢

热点阅读