区块水平,垂直以及浮动后居中方式小结

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <!--<link rel="stylesheet" href="global.css"/>-->
    <style>
        .big1{
            width: 1200px;
            height: 200px;
            background-color: darkkhaki;
            position: relative;
        }
        .childO{
            width: 50px;
            height: 50px;
            background-color: #ac2925;
            /*在设置了宽度的情况下,子级在父级里自适应水平居中*/
            margin: auto;
        }
        .childT{
            width: 50px;
            height: 50px;
            background-color: #ff335e;
            margin: auto;
            /*水平、垂直都居中,利用定位的方式,父级必须先设定非静态定位*/
            position: absolute;
            top: 0px;
            left: 0px;
            right: 0px;
            bottom: 0px;
        }
        /*垂直居中*/
        .childTh{
            width: 100px;
            height: 100px;
            background-color: green;
            position: absolute;
            top: 50%;
            margin-top: -50px;
        }
        .big2{
            width: 1200px;
            height: 200px;
            margin-top: 50px;
            background-color: #bec7d0;
            position: relative;
        }
        .childOO{
            width: 150px;
            height: 150px;
            background-color: #407cac;
            /*浮动水平\垂直居中*/
            float: left;
            display: inline-block;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -75px;
            margin-top: -75px;
        }
    </style>
</head>
<body>
<!--水平居中-->
    <div class="big1">
        <div class="childO">水平居中</div>
        <div class="childT">水平、垂直都居中</div>
        <div class="childTh">垂直居中</div>
    </div>
    <div class="big2">
        <div class="childOO">浮动水平、垂直居中</div>
    </div>
 </body>
</html>
</pre><br />
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值