码迷,mamicode.com
首页 > 其他好文 > 详细

盼盼Degenerate——清除浮动的方法

时间:2017-08-26 17:13:51      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:generate   meta   ott   device   use   blog   rate   lock   set   

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
</head>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
header{
width: 100%;
background: orange;
text-align: center;
font-size: 24px;
padding: 10px 0;
}

.box{
width: 100%;
border: 2px solid #000000;
}


.box li{
width: 25%;
height: 100px;
background: pink;
float: left;
margin: 10px ;
}
div.carousel{
width: 100%;
height: 300px;
background: aquamarine;
}
footer{
width: 100%;
position: fixed;
bottom: 0;
background: orange;
text-align: center;
font-size: 24px;
padding: 10px 0;
}
</style>
<body>
<header>头部</header>
<ul class="box">
<li></li>
<li></li>
<li></li>
</ul>
<div class="carousel">
</div>
<footer>底部</footer>
</body>
</html>

此时在浏览器中的样式

技术分享

 

第一种方法

使用overflow: hidden;

给父元素添加overflow: hidden;

技术分享

 

 第二种方法

在子元素后边添加一个空div

<ul class="box">
<li></li>
<li></li>
<li></li>
<div class="clearfix"></div>
</ul>

css样式

.clearfix{
clear: both;
}

第三种使用伪元素

css代码

.box:after{
content: ‘‘;
display: block;
clear: both;
}

第四种浮动父元素

.box{
width: 100%;
border: 2px solid #000000;
float: left;
}

但是此时在浏览器我们可以看到并不是我们想要的效果

技术分享

 

 为了解决这个问题 我们在父元素下面添加一个空div

<body>
<header>头部</header>
<ul class="box">
<li></li>
<li></li>
<li></li>
</ul>
<div class="clearfix"></div>
<div class="carousel">
</div>
<footer>底部</footer>
</body>

 css样式

.clearfix{
clear: both;
}

这样就解决了这个问题

 

盼盼Degenerate——清除浮动的方法

标签:generate   meta   ott   device   use   blog   rate   lock   set   

原文地址:http://www.cnblogs.com/panpan-degenerate/p/7435555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!