while discussing a margin issue in the css forest group, i accidentally discovered that overflow can also be used to clear floats. hey, this method is not only easy to use, but also supported by ff, op, and ie7. from now on, you can say goodbye to the long compatibility another poor method of clearing floats in ff.
the method is really simple, just add the overflow attribute to the label that needs to be cleared.
css code
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 code
<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>
where zoom is prepared for 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"> <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ɭ" /> <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> <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> <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> <div> <div><img src="/static/imghwm/default1.png" data-src="http://www.google-analytics.com/urchin.js" class="lazy" alt="The best way to clear floating css for IE7, FF and OP" /></div> <div> <p class="fn n"><strong>ghost</strong> <strong>zhang</strong></p> <p><strong>email:</strong><a href="mailto:lovej1bz@gmail.com">lovej1bz@gmail.com</a></p> <p><strong>qq:</strong><a href="tencent://message/?uin=22168741&site=webrebuild.org&menu=yes">22168741</a></p> <p><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" rel="me">http://forest.blogbus.com</a> </div> </div> </div> </body> </html>
note: i forgot a very important point. not all overflow attributes have the same effect. for example, the visible attribute can only work on ie. an example can be seen here:
<?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"> <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ɭ" /> <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 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;height:80px;margin-right:2px;padding:0 10px;background-color:#83b1df;line-height:80px;} .demo{clear:both;border:1px solid #ff00ff;margin-bottom:5px;} .overflow{overflow:auto;zoom:1;background-color:#43ff73;} .overflow1{overflow:hidden;zoom:1;background-color:#43ff73;} .overflow2{overflow:visible;zoom:1;background-color:#43ff73;} /*]]>*/ </style> </head> <body> <p>overflow的visible属性只对ie起作用,auto/hidden可对ff、op起作用。</p> <div> <ul> <li>overflow:auto;</li> <li>overflow:auto;</li> <li>overflow:auto;</li> <li>overflow:auto;</li> <li>overflow:auto;</li> <li>overflow:auto;</li> </ul> </div> <div> <ul> <li>overflow:hidden;</li> <li>overflow:hidden;</li> <li>overflow:hidden;</li> <li>overflow:hidden;</li> <li>overflow:hidden;</li> <li>overflow:hidden;</li> </ul> </div> <div> <ul> <li>overflow:visible;</li> <li>overflow:visible;</li> <li>overflow:visible;</li> <li>overflow:visible;</li> <li>overflow:visible;</li> <li>overflow:visible;</li> </ul> </div> <div> <ul> <li>no overflow</li> <li>no overflow</li> <li>no overflow</li> <li>no overflow</li> <li>no overflow</li> <li>no overflow</li> </ul> </div> <div> <div> <div><img src="http://img68.imageshack.us/img68/8708/myThe best way to clear floating css for IE7, FF and OP9we.gif" alt="The best way to clear floating css for IE7, FF and OP" /></div> <div> <p class="fn n"><strong>ghost</strong> <strong>zhang</strong></p> <p><strong>email:</strong><a href="mailto:lovej1bz@gmail.com">lovej1bz@gmail.com</a></p> <p><strong>qq:</strong><a href="tencent://message/?uin=22168741&site=webrebuild.org&menu=yes">22168741</a></p> <p><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" rel="me">http://forest.blogbus.com</a> </div> </div> </div> </body> </html>
there is a problem in this case. if there is a height and the content exceeds the height, defining auto or hidden may have some unwanted effects. appear. here is a solution: for ie6 and below, you can directly define the height; for ie7, ff, and op, you can define min-height.
css code:
overflow { height:auto; _height:200px; min-height:200px; verflow:auto; zoom:1; _overflow:visible; }

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

There is an HTML attribute that does exactly what you think it should do:


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools