浮动占位情况

讲讲自己试的浮动元素占位情况。

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        div.one {
            background-color: red;
            width: 450px;
        }

        img {
            width: 200px;
            float: right
        }
        .two{
            width:100px;
            height:100px;
            background-color: green;
            display: inline-block;
        }
        .three{
            width:100px;
            height:100px;
            background-color:blue;
            display: inline-block;
        }
        .four{
            width:100px;
            height:100px;
            background-color: gold;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="one">
        <img src="img/1.jpg" alt="">
        <div>
            <div class="two"></div>
            <div class="three"></div>
            <div class="four"></div>
        </div>
    </div>
</body>
</html>

效果展示:

效果展示:

总结:浮动的盒子不占用原来的位置,它下面的盒子会上来占用它原来的位置。浮动了的盒子变成行内块元素,占用现在的位置。
我之前的理解错了,以为浮动的盒子悬浮在上面,它后面的盒子上来占用位置,被浮动的盒子覆盖,以为浮动的盒子完全不占位置的,其实还是站位置的,只是可能不是占原来的位置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值