当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > Firefox和IE通用的三则网站重构实用技巧
使用zoom、overflow解决IE6、IE7、FF下嵌套容器清除浮动问题

| <style type="text/css"> .content{ border:10px solid #F00;} .text{ width:200px; height:300px; background:#000;} </style> <body bgcolor="#FFFFFF"> <div class="content"> <div class="text"></div> </div> </body> |

| <style type="text/css"> .content{ border:10px solid #F00; width:200px; overflow:auto;} .text{ width:200px; height:300px; background:#000; float:left;} </style> <body bgcolor="#FFFFFF"> <div class="content"> <div class="text"></div> </div> </body> |
除此之外还有一种比较特殊的情况,如果在不设定content宽度的情况下,仅仅使用overflow:auto,在IE5.5+下是无法实现清除浮动的效果的。为此我们需要使用一个IE的私有属性zoom来使IE下达到所需效果。
代码如下:
| <style type="text/css"> .content{ border:10px solid #F00; overflow:auto; zoom:1;} .text{ width:200px; height:300px; background:#000; float:left;} </style> <body bgcolor="#FFFFFF"> <div class="content"> <div class="text"></div> </div> </body> |
使用链接样式模拟图片热区

| <style type="text/css"> #banner{ width:400px; height:100px; background:#959595;} #banner a{ float:left;} #banner a.link1{ width:100px; height:50px; background:#F00; margin:20px 0 0 20px;} #banner a.link2{ width:200px; height:80px; background:#F00; margin:10px 0 0 50px;} </style> <body bgcolor="#FFFFFF"> <div id="banner"> <a href="#" class="link1"></a> <a href="#" class="link2"></a> </div> </body> |

| <style type="text/css"> ul{ margin:0; padding:0 0 20px 0; list-style:none; width:380px; overflow:auto; background:#959595;} ul li{ float:left; display:inline; width:100px; height:80px; background:#F00; margin:20px 0 0 20px;} </style> <body bgcolor="#FFFFFF"> <ul> <li>4</li> <li>3</li> <li>2</li> <li>1</li> </ul> </body> |
评论 (0) All