首页 > 代码库 > 块状元素居中

块状元素居中

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
      .bigBox{
        width: 200px;
        height: 200px;
        border: 1px solid #ccc;
        position: relative;
      }
      .smailBox{
        width: 50px;
        height: 50px;
        border: 1px solid #ccc;
        position: absolute;
        margin: auto;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
      }
    </style>
</head>
<body>
    <div class="bigBox">
      <div class="smailBox"></div>
    </div>
</body>
</html>

 

不用任何计算。。。

块状元素居中