南强小屋 Design By 杰米

一、清除浮动的方式一

给前面一个父元素设置高度,​注意:企业开发中能不写高度就不写高度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>D131_ClearFloat</title>
    <style>
        .smallbox1{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
            float:right;
​
        }
        .smallbox2{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox3{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox4{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox5{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox6{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .bigbox1,.bigbox2{
            /*width:400px;*/
            /*width:400px;*/
            background-color: green;
            border:3px black solid;
        }
</style>
</head>
<body>
<div class="bigbox1">
    <div class="smallbox1"></div>
    <div class="smallbox2"></div>
    <div class="smallbox3"></div>
</div>
<div class="bigbox2">
    <div class="smallbox4"></div>
    <div class="smallbox5"></div>
    <div class="smallbox6"></div>
</div>
</body>
</html>

HTML清除浮动的其中两种方式

二、清除浮动的第二种方式

给后面的属性添加clear属性

clear属性取值:

none:默认取值,按照浮动元素的排序规则进行排序(左浮动找左浮动,右浮动找右浮动)

left:不要找前面的左浮动元素

right:不要找前面的右浮动元素

both:不要找前面的左浮动和有浮动元素

例如:我们不设置大盒子的宽高,小盒子会把大盒子撑起来,但是两个大盒子会因此而在一行上

 .smallbox1{
            width:100px;
            height: 100px;
            float:left;
            background-color: red;
            border:2px solid black;
        }
        .smallbox2{
            width:100px;
            height: 100px;
            float:left;
            background-color: red;
            border:2px solid black;
        }
        .smallbox3{
            width:100px;
            height: 100px;
            float:left;
            background-color:blue;
            border:2px solid black;
        }
        .smallbox4{
            width:100px;
            height: 100px;
            float:left;
            background-color: blue;
            border:2px solid black;
        }
    </style>
</head>
<body>
<div class="bigbox1">
    <div class="smallbox1"></div>
    <div class="smallbox2"></div>
</div>
<div class="bigbox2">
    <div class="smallbox3"></div>
    <div class="smallbox4"></div>
</div>
</body>

HTML清除浮动的其中两种方式

我们使用clear属性在第三个小盒子上,这样就可以另起一行了(第四个就不用,因为我们就想让第三个挨着第四个),只需要第三个小盒子的代码修改代码

      .smallbox3{
            clear:left;
            width:100px;
            height: 100px;
            float:left;
            background-color:blue;
            border:2px solid black;
        }

HTML清除浮动的其中两种方式

​注意点:margin属性失效了,不失效的方式我们下次再说。

三、源码:

D131_ClearFloat.html

D132_CLearAttribute.html

地址:

https://github.com/ruigege66/HTML_learning/blob/master/D131_ClearFloat.html

https://github.com/ruigege66/HTML_learning/blob/master/D132_CLearAttribute.html

总结

以上所述是小编给大家介绍的HTML清除浮动的其中两种方式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

标签:
html,清除浮动,html,浮动

南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米

评论“HTML清除浮动的其中两种方式”

暂无HTML清除浮动的其中两种方式的评论...

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?