首页 > 开发 > CSS > 正文

IE6和IE7中行内元素后的浮动元素被折行的问题解决

2024-07-11 08:25:43
字体:
来源:转载
供稿:网友

一、实例

XML/HTML Code复制内容到剪贴板
  1. <ul class="list">    <li><a href="#" title="">新闻一Benjamin</a><span>2014-05-06</span></li>  
  2.  <li><a href="#" title="">新闻一Benjamin</a><span>2014-05-06</span></li>    <li><a href="#" title="">新闻一Benjamin</a><span>2014-05-06</span></li>  
  3.  <li><a href="#" title="">新闻一Benjamin</a><span>2014-05-06</span></li>   </ul>  
CSS Code复制内容到剪贴板
  1. <style type="text/css">     body,ul{padding:0;margin:0;}   
  2.  ul{list-style-type: none;border:1px solid #ccc;}     li{padding-left:0;}   
  3.  .list{width:300px;margin:100px auto;}     .list li{height:24px;line-height: 24px;border-bottom: 1px solid #ccc;margin-bottom:-1px;padding-left: 10px;}   
  4.  .list li span{float:rightright;margin-right:10px;}     .list li .float_a{float:left;}   
  5.  .fix {*zoom:1;}     .fix:after {display: block; content: ".";visibility: hidden;clear: both;height: 0;overflow: hidden;}   
  6. </style>  

二、各浏览器效果图
2016627120709205.gif (310×540)

三、原因分析
1.标准参考:
W3C CSS2.1规范文档里对于浮动元素与非浮动行内元素相邻时的情况有如下解释。以下是关键段落:
A floated box is shifted to the left or right until its outer edge touches the containing block edge or the outer edge of another float. If there’s a line box, the top of the floated box is aligned with the top of the current line box.
由上面的描述可以得到以下结论:如果一个元素浮动前是一个行内元素,则该元素浮动后,顶部应与其之前所在的行框顶部对齐。
2.问题描述:
IE6 IE7 IE8(Quick)下,若浮动元素之前存在兄弟行内非浮动元素,IE 会将浮动元素所在的“当前行”认为是其前边的兄弟行内元素所产生的匿名框的底边,导致该浮动元素折行。

四、解决方案
1.全浮动

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表