话不多说先上要实现的效果:(很简单水平居中)

单个div水平垂直居中的方式

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <style type="text/css">
        /* 方式一 */
        .box{
            width: 100px;
            height: 100px;
            color: #fff;
            background: #000000;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
        }
    </style>
    <body>
        <div class="box">方式一</div>
    </body>
</html>
        /* 方式二 */
        .box{
            width: 100px;
            height: 100px;
            color: #fff;
            background: #000000;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -50px;
            margin-top: -50px;
        }
        /* 方式三 */
        .box{
            width: 100px;
            height: 100px;
            color: #fff;
            background: #000000;
            position: absolute;
            top:50%;
            left:50%;
            transform:translate(-50%,-50%);
        }

 

相关文章:

  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-05-31
  • 2022-12-23
猜你喜欢
  • 2022-01-05
  • 2021-12-01
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-08-28
相关资源
相似解决方案