评论

收藏

[Html/CSS] 对于IE7、FF、OP清除浮动的最优方法第1/2页

开发技术 开发技术 发布于:2021-06-29 12:01 | 阅读数:288 | 评论:0

在CSS森林群里讨论一个margin的问题中无意间发现overflow也可以用来清除浮动,嘿嘿,这个方法不单使用简单,而且FF、OP、IE7都支持,从此可以告别那又长兼容性又差的FF清浮动的方法了。  

方法真的很简单,只要为需要清浮动的标签加上overflow这个属性。  
css代码
ul{ 
list-style:none; 
height:auto; 
margin:0;p 
adding:0; 
background-color:#436973; 
} 
li{ 
float:left; 
width:80px; 
height:80px; 
background-color:#83B1DF; 
} 
.demo{ 
clear:both; 
border:1px solid #FF00FF; 
margin-bottom:5px; 
} 
.overflow{ 
overflow:auto; 
zoom:1; 
background-color:#43FF73; 
} 
ul{ 
list-style:none; 
height:auto; 
margin:0; 
padding:0; 
background-color:#436973; 
} 
li{ 
float:left; 
width:80px; 
height:80px; 
background-color:#83B1DF; 
} 
.demo{ 
clear:both; 
border:1px solid #FF00FF; 
margin-bottom:5px; 
} 
.overflow{ 
overflow:auto; 
zoom:1; 
background-color:#43FF73; 
}
HTML代码
<div class="demo">  
<ul class="overflow">  
<li>1</li>  
<li>2</li>  
<li>3</li>  
<li>4</li>  
<li>5</li>  
<li>6</li>  
<li>7</li>  
<li>8</li>  
<li>9</li>  
</ul>  
</div>  
<div class="demo">  
<ul>  
<li>1</li>  
<li>2</li>  
<li>3</li>  
<li>4</li>  
<li>5</li>  
<li>6</li>  
<li>7</li>  
<li>8</li>  
<li>9</li>  
</ul>  
</div>
其中zoom是为了IE6准备的。
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn"> <head> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="utf-8" /> <meta name="robots" content="all" /> <meta name="author" content="Ghost" /> <meta name="Copyright" content="CSSForest" /> <meta name="Description" content="CSS&#621;" /> <meta name="Keywords" content="CSS,web标准,web,Blog,,XHTML,CSSForest,CSS森林" /> <title>Overflow hack Demo|www.CSSForest.org</title> <link rel="Shortcut Icon" href="/favicon.ico" type="image/x-icon" /> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> <script type="text/javascript">_uacct = "UA-780254-5";urchinTracker();</script> <style type="text/css"> /*<![CDATA[*/ .copyright{position:absolute;bottom:60px;left:10px;width:300px;height:200px;line-height:1.2em;} .copyright a:link{color:#666666;text-decoration:none;} .copyright a:hover{color:#CC9900;text-decoration:underline;} ul{list-style:none;height:auto;margin:0;padding:0;background-color:#436973;} li{float:left;width:80px;height:80px;background-color:#83B1DF;} .demo{clear:both;border:1px solid #FF00FF;margin-bottom:5px;} .overflow{overflow:auto;zoom:1;background-color:#43FF73;} /*]]>*/ </style> </head> <body> <p></p> <div class="demo">   <ul class="overflow">     <li>1</li>     <li>2</li>     <li>3</li>     <li>4</li>     <li>5</li>     <li>6</li>     <li>7</li>     <li>8</li>     <li>9</li>   </ul> </div> <div class="demo">   <ul>     <li>1</li>     <li>2</li>     <li>3</li>     <li>4</li>     <li>5</li>     <li>6</li>     <li>7</li>     <li>8</li>     <li>9</li>   </ul> </div> <div class="copyright">   <div class="vcard">   <div class="logodiv"><img class="logo" src="http://img68.imageshack.us/img68/8708/mylogo9we.gif" alt="LOGO" /></div>   <div class="info">     <p class="fn n"><strong class="given-name">Ghost</strong> <strong class="family-name">Zhang</strong></p>     <p><strong>Email:</strong><a href="mailto:lovej1bz@gmail.com" class="email">lovej1bz@gmail.com</a></p>     <p class="qq"><strong>QQ:</strong><a href="tencent://message/?uin=22168741&amp;Site=webrebuild.org&amp;Menu=yes" class="uid">22168741</a></p>     <p class="org"><strong>ORG:</strong><a href="http://www.webrebuild.org">WebReBuild.ORG</a> <a href="http://www.cssforest.org/">www.CSSForest.ORG</a></p>     <strong>Blog:</strong><a href="http://forest.blogbus.com" class="url" rel="me">http://forest.blogbus.com</a> </div>   </div> </div> </body> </html>
  [Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
                            12阅读全文
关注下面的标签,发现更多相似文章