为了账号安全,请及时绑定邮箱和手机立即绑定

怎样进行浮动的清除?

怎样进行浮动的清除?

xiaoxiaoxiao遥 2017-05-03 19:56:00
查看完整描述

3 回答

已采纳
?
西兰花伟大炮

TA贡献376条经验 获得超318个赞

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .container{
            height: auto;
            width: 400px;
            margin: 100px auto;
            border: 2px dotted red;
        }
        .item{
            float: left;
            width: 50px;
            height: 50px;
            background: yellow;
            margin-right: 10px;
        }
        /*.clearfix::after{
            content: "";
            height: 0;
            clear: both;
            display: block;
        }*/
        .last{
            clear: both;
        }
    </style>
</head>
<body>
    <div class="container clearfix" >
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="last"></div>
    </div>
</body>
</html>

两种方法,一种伪类,一种是在末尾添加空元素,欢迎采纳

查看完整回答
1 反对 回复 2017-05-03
?
frece

TA贡献36条经验 获得超15个赞

<!DOCTYPE html>
<html> 
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    	.fl{float: left;}
   	 	.fr{float: right;}
    	.square{width: 200px; height: 200px; border: 1px solid #0000ff;}
    	.clear{clear: both;}
    </style>
</head> 
<body>
	<div>
		<div class="square fl">square1</div>
		<div class="square fr">square2</div>
		<div class="clear"></div>
	</div>
	<label>test text</label>	
</body> 
</html>

大型项目里都会定义一个 .clear 的样式  需要的时候直接用,上边代码你可以把<div class="clear"></div>去掉看看区别

一般情况下, 有浮动必有clear

查看完整回答
反对 回复 2017-05-03
  • 3 回答
  • 0 关注
  • 1313 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信