首页 > 其他 > 详细

margin负——块元素垂直、水平居中

时间:2020-12-13 11:57:14      阅读:30      评论:0      收藏:0      [点我收藏+]
技术分享图片
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垂直居中</title>
    <style>
        .boxBig {
            /* 子绝父相 */
            position: relative;
            width: 600px;
            height: 700px;
            background-color: gray;
        }
        
        .box {
            position: absolute;
            /* 水平居中 2行——自己width的一半*/
            left: 50%;
            margin-left: -150px;
            /* 垂直居中 2行——自己height的一半*/
            top: 50%;
            margin-top: -150px;
            width: 300px;
            height: 300px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="boxBig">大盒子
        <div class="box">盒子</div>
    </div>
</body>

</html>

margin负——块元素垂直、水平居中

原文:https://www.cnblogs.com/icemiaomiao3/p/14128110.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!