栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

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

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一、实例

XML/HTML Code复制内容到剪贴板
  1.   
  2.  
  3. 新闻一Benjamin2014-05-06
  4.   
  5.  
  6. 新闻一Benjamin2014-05-06
  7.   
  8.  
  9. 新闻一Benjamin2014-05-06
  10.   
  11.  
  12. 新闻一Benjamin2014-05-06
  13.   
  14.   
CSS Code复制内容到剪贴板
  1.   
  2.  body,ul{padding:0;margin:0;}   
  3.  ul{list-style-type: none;border:1px solid #ccc;}   
  4.  li{padding-left:0;}   
  5.  .list{width:300px;margin:100px auto;}   
  6.  .list li{height:24px;line-height: 24px;border-bottom: 1px solid #ccc;margin-bottom:-1px;padding-left: 10px;}   
  7.  .list li span{float:rightright;margin-right:10px;}   
  8.  .list li .float_a{float:left;}   
  9.  .fix {*zoom:1;}   
  10.  .fix:after {display: block; content: ".";visibility: hidden;clear: both;height: 0;overflow: hidden;}   
  11.   

二、各浏览器效果图
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.全浮动

CSS Code复制内容到剪贴板
  1.   
  2.  "float_a" href="#" title="">新闻一Benjamin 2014-05-06
  3.   
  4.  "float_a" href="#" title="">新闻一Benjamin 2014-05-06
  5.   
  6.  "float_a" href="#" title="">新闻一Benjamin 2014-05-06
  7.   
  8.  "float_a" href="#" title="">新闻一Benjamin 2014-05-06
  9.   
  10.   

2.放置浮动元素在前

CSS Code复制内容到剪贴板
  1.   
  2.  
  3. 2014-05-06"#" title="">新闻一Benjamin 
  4.   
  5.  
  6. 2014-05-06"#" title="">新闻一Benjamin 
  7.   
  8.  
  9. 2014-05-06"#" title="">新闻一Benjamin 
  10.   
  11.  
  12. 2014-05-06"#" title="">新闻一Benjamin 
  13.   
  14.   

3.定位position
4.IE Hack+margin负值

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/217652.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号