清除浮动
2015-09-05 17:24
323 查看
两种清除浮动方法:
1.p{clear:both/left/right;}
适应范围:紧邻的块级元素<span style="font-size:14px;"><html> <head> <style type="text/css"> #style0{ width:300px; } #style1{ background:#FF0000; float:right; /*设置浮动向右*/ } #style2{ background:#00FF00; clear:both; /*清除块1对块2的右浮影响*/ } </style> </head> <body> <div id="style0"> <div id="style1">块1:how are you</div> <div id="style2">块2:i am fine</div> </div> </body> </html></span>
清除前:
清除后:
2、p{width:100%(或设置定宽);overflow:hidden;}
适应范围:块级元素嵌套块级元素
width设置为100%就是继承父容器的宽度。左右撑满整个容器,为自己清除浮动创建条件。再加溢出隐藏,就可以把包裹浮动的部分去除。
<span style="font-size:14px;">#style0{ background:#000000; width:300px; /*父级容器不会显示黑色*/ } #style1{ background:#FF0000; } #style2{ background:#00FF00; float:left; /*设置块二左浮*/ }</span>
<span style="font-size:14px;">#style0{ background:#000000; width:300px; overflow:hidden; /*父级容器会显示黑色*/ }</span>
相关文章推荐
- HDU 4414 Finding crosses
- UITableView 的使用的小技巧
- 游戏的AOI算法
- 第五章 模版和Static Media
- object references an unsaved transient instance - save the transient instance before flushing
- 有图有话 | 高效人士的一天,你能做到几条?
- iOS 第三方分享
- fragment 详解(三)
- 黑马程序员--IO流(操作对象、管道流、RandomAccessFile)
- nodejs websocket 事件中传递的参数不对导致nodejs崩溃
- 屏幕的适配
- 语料库
- window ip地址分配
- STL — 关联容器
- 密码学4——Java 加密解密之消息摘要算法(MD5 SHA MAC)
- CSS设置滚动条样式
- hiho#14
- C++ DateTime 结构
- [翻译]程序员需要掌握的6项相关技能
- php goto操作符