码迷,mamicode.com
首页 > 其他好文 > 详细

盒子居中

时间:2020-11-24 12:31:57      阅读:7      评论:0      收藏:0      [点我收藏+]

标签:splay   initial   rgb   ati   pre   class   sla   style   bsp   

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .father {
        width: 300px;
        height: 300px;
        display: flex;
    }

    .child {
        margin: auto;
    }

    .father1 {
        width: 300px;
        height: 300px;
        position: relative;
    }

    .child1 {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .father2 {
        width: 300px;
        height: 300px;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .child2 {}
</style>

<body>
    <!-- flexbox布局 -->
    <div class="father">
        <div class="child">
            qweeeeeeeeeee
        </div>
    </div>
    <!-- 子绝父相 -->
    <div class="father1">
        <div class="child1">
            qweeeeeeeeeee
        </div>
    </div>
    <!-- flex布局 -->
    <div class="father2">
        <div class="child2">
            qweeeeeeeeeee
        </div>
    </div>
</body>

</html>

 

盒子居中

标签:splay   initial   rgb   ati   pre   class   sla   style   bsp   

原文地址:https://www.cnblogs.com/lzhflzjx/p/14009635.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!