
<!doctype html>
<html>
<head>
<style>
.fr{float:right;display:inline}
li{border:1px solid #ccc;width:150px;height:18px}
li img{width:16px;height:16px}
ul{widht:100%;height:100%}
</style>
</head>
<body>
<ul><li>哈哈<img class='fr' src='aaa.gif'></li><ul>
</body>
</html>
上述代码的 目的 是让 图片在Li内部靠右浮动,在ie8+ ,以及chrome 之类的浏览器均正常,但在ie7 - 之下 不正常,第一个想到的就是浮动闭合问题
于是修改成
<!doctype html>
<html>
<head>
<style>
.fr{float:right;display:inline}
li{border:1px solid #ccc;width:150px;height:18px}
li img{width:16px;height:16px}
ul{widht:100%;height:100%} .clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix{*zoom:1;}
</style>
</head>
<body>
<ul><li class='clearfix'>哈哈<img class='fr' src='aaa.gif'></li><ul>
</body>
</html>
发现效果未变,还是那个图被挤在li下方
最终再几经测试之后,终于明白 应该把那个文字也要进行浮动,但为什么文字也需要浮动 还是没有具体想明白,有清楚的兄弟告诉我一下,具体代码如下
<!doctype html>
<html>
<head>
<style>
.fr{float:right;display:inline}
.fl{float:left;display:inline}
li{border:1px solid #ccc;width:150px;height:18px}
li img{width:16px;height:16px}
ul{widht:100%;height:100%} .clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix{*zoom:1;}
</style>
</head>
<body>
<ul><li class='clearfix'><span class='fl'>哈哈</span><img class='fr' src='aaa.gif'></li><ul>
</body>
</html>
参考
《哪些年我们一起清除过的浮动》http://www.iyunlu.com/view/css-xhtml/55.html