当前位置:常识集 > 智慧生活 > 生活常识 > css清除浮动常用的两种方法
手机版

css清除浮动常用的两种方法

来源:常识集 阅读:7.14K 次

css清除浮动在网页布局中经常试用到的,下面两个方法可以实现浮动

第一种方法是 clear:both;

(01)css代码{ width:300px; background:#CCC; padding-bottom:10px; margin-bottom:10px;} { width:145px; height:100px; float:left; background:#F0F;} t{ width:145px; height:100px; float:right; background:#F00;}rboth{ clear:both;}html代码<div class="Box"><div class="left"></div><div class="right"></div><div class="clearboth"></div></div>

css清除浮动常用的两种方法

第二种方法是用伪类:after写入空白元素来清

(01)IE8以上和非IE浏览器才完全支持:after,IE6、IE7需要用ie的私有属性zoom来触发hasLayout才能完美兼容,没有增加多余的标签,推荐使用。css代码{ width:300px; background:#CCC; padding-bottom:10px; margin-bottom:10px;} { width:145px; height:100px; float:left; background:#F0F;} t{ width:145px; height:100px; float:right; background:#F00;}rfloat:after{ display:block; clear:both; content:""; overflow:hidden; height:0}rfloat{ zoom:1;}html代码<div class="Box"><div class="left"></div><div class="right"></div><div class="clearboth"></div></div>

本文链接:https://www.changshiji.com/zhsh/changshi/6djrl.html
#CSS

Copyright © 2024. 常识集 All right reserved. 浙ICP备20202586号-2

文字美图素材,版权属于原作者。部分文章内容由网友提供推送时因种种原因未能与原作者联系上,若涉及版权问题,敬请原作者联系我们,立即处理。