div水平垂直居中

<style>
        html,
        body,
        div {
            margin: 0;
            padding: 0
        }
        
        .bigBox {
            position: relative;
            width: 300px;
            height: 300px;
            background-color: #000;
            margin: 300px auto;
        }
        
        .smallBox {
            width: 100px;
            height: 100px;
            background-color: #ff0000;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-top: -50px;
            margin-left: -50px;
        }
</style>
<body>
   <div class="bigBox">
        <span class="smallBox"></span>
   </div>
</body>
posted @ 2021-02-21 13:52  BesePawn  阅读(44)  评论(0编辑  收藏  举报