clear属性的作用

clear属性用于在块级元素中清除浮动效果的其值可以设置成:

clear:both 清除左右两边的的浮动
clear:left 清除左边的浮动
clear: right 清除右边浮动
clear: none 左右都有浮动效果

与float的区别不同的是,clear是清除float的之前的设置效果重新在新的一行生成其设置的值的效果

演示代码:
<style>
        body{
            width: 500px;
            height: 400px;
            border: 1px solid #000;
        }
        .div1 {
            width: 100px;
            height: 100px;
            background-color: rgb(0, 255, 255);
            text-align: center;
            line-height: 100px;
            margin: 10px  10px;
            float: left;

        }

        .div2 {
            width: 100px;
            height: 100px;
            line-height: 100px;
            background-color: rgb(10, 200, 255);
            text-align: center;
            margin: 10px;
            float: left;
        }

        .div3 {
            width: 100px;
            height: 100px;
            line-height: 100px;
            background-color: rgb(90, 0, 255);
            text-align: center;
            margin: auto 10px;
            clear: left;
            float: right;

        }

        .div4 {
            width: 100px;
            height: 100px;
            line-height: 100px;
            background-color: rgb(0, 0, 255);
            text-align: center;
            margin: auto 10px;
            clear: right;
            float: left;
        }
    </style>
<body>
<div class="div1">A</div>
<div class="div2">B</div>
<div class="div3">C</div>
<div class="div4">D</div>
</body>
结果:

在这里插入图片描述

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值