css清除float方法

工作的忙碌,没时间总结如何处理清除网页float的经验。

昨天去面试了下,说到这问题,觉的很有必要总结下。

刚下火车,早上精力比较充沛。哈哈

方法一:使用空标签清除浮动:

css code:
<style type="text/css">
<!--
html,body,h1,h2,h3,h4,h5,h6,ul,ol,li,p{
margin:0;
padding:0
}
body{
font: 400 12px/18px "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color:#666;
}
#layout{
background:#F3F5F9;
}
#l_block{
background:#ccc;
width:300px;
height:200px;
float:left;
}
#r_block{
background:#f00;
width:100px;
height:100px;
float:right;
}
.c_f{
clear:both;
}
-->
</style>

html code:
<div id="layout">
<div id="l_block">left block content</div>
<div id="r_block">right block content</div>
<div class="c_f">This is a content area</div> <!--clear float-->
</div>


方法二:使用overflow属性;

css code:
<style type="text/css">
<!--
html,body,h1,h2,h3,h4,h5,h6,ul,ol,li,p{
margin:0;
padding:0
}
body{
font: 400 12px/18px "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color:#666;
}
#layout{
overflow:auto;
zoom:1; /*ie6*/
background:#F3F5F9;
}
#l_block{
background:#ccc;
width:300px;
height:200px;
float:left;
}
#r_block{
background:#f00;
width:100px;
height:100px;
float:right;
}
-->
</style>

html code:
<div id="layout">
<div id="l_block">left block content</div>
<div id="r_block">right block content</div>
</div>


方法三:使用after伪对象清楚浮动。

css code:
<style type="text/css">
<!--
html,body,h1,h2,h3,h4,h5,h6,ul,ol,li,p{
margin:0;
padding:0
}
body{
font: 400 12px/18px "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color:#666;
}
#layout{
background:#F3F5F9;
}
#layout:after{
height:0;
display:block;
clear:both;
content:"";
visibility:hidden;
}
#l_block{
background:#ccc;
width:300px;
height:200px;
float:left;
}
#r_block{
background:#f00;
width:100px;
height:100px;
float:right;
}
-->
</style>

html code:
<div id="layout">
<div id="l_block">left block content</div>
<div id="r_block">right block content</div>
</div>


start work:先总结这,还有待补充解释.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值