ie6/7/8中span右浮动折行问题的解决方案

浮动标准:

W3C CSS 2.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.

由上面的描述可以得到以下结论:如果一个元素浮动前是一个行内元素,则该元素浮动后,顶部应与其之前所在的行框顶部对齐。

问题描述:

IE6 IE7 IE8(Q) 下,若浮动元素之前存在兄弟行内非浮动元素,IE 会将浮动元素所在的“当前行”误认为是其前边的兄弟行内元素所产生的匿名框的底边,导致该浮动元素折行;

1 <div style="border:1px solid black; font:14px Verdana; padding:5px;">
2     <span style="background:gold;">Text1</span>
3     <span style="background:lightblue;">Text2</span>
4     <span style="background:pink;">Text3</span>
5     <span style="background:greenyellow;">Text4</span>
6     <span style="background:peru;">Text5</span>
7     <span style="background:tomato; float:right;">Some text aligning right</span>
8 </div>

解决方法:

方案一:把Text1/Text2/Tex3/Text4/Text5均设置浮动(float:left);

方案二:将Some text aligning right设置他的margin-top使其对其Text1-5;

方案三:使用绝对定位(position:absolute)模拟右浮动(float:right);

方案四:将浮动的元素调到非浮动的元素之前:

1 <div style="border:1px solid black; font:14px Verdana; padding:5px;">
2 <span style="background:tomato; float:right;">Some text aligning right</span>
3 <span style="background:gold;">Text1</span>
4 <span style="background:lightblue;">Text2</span>
5 <span style="background:pink;">Text3</span>
6 <span style="background:greenyellow;">Text4</span>
7 <span style="background:peru;">Text5</span>
8 </div>

方案四比较简单

时间: 2024-08-01 02:11:23

ie6/7/8中span右浮动折行问题的解决方案的相关文章

IE6下span右浮动换行怎么处理

IE6下span右浮动换行怎么处理:在编写新闻列表的时候,一般要求左边是新闻标题,右边是新闻发布时间.时间一般会放在<span>标签中,并将其右浮动.代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.51texiao.cn/" /&g

ie下li标签中span加float:right不换行问题解决方案

在IE6,IE7下使用标签时,在加入右浮动样式(float:right)后,会换行的bug解决方案:bug案例:新闻列表中,为使时间右对齐,加右浮动产生换行 <ul> <li><a href=“#”>BEST SUSHI MENU</a> <span>2012-12-24</span></li> <li><a href=“#”>BEST SUSHI MENU</a> <span&g

CSS中定位和浮动对行内元素的宽高的影响

行内元素的大小是由元素里面的内容撑开的宽高决定的,就算在css中对行内元素设置width,height.行内元素也会忽略宽高的设置. 但是当行内元素使用position:absolute或者position:fixed或者使用float属性时,width和height的设置能起作用. 因为在以上三种情况下,行内元素的display从inline变为block <style> span{ background-color:red; width:100px; height:100px; float

为什么右浮动以后顺序颠倒了

为什么右浮动以后顺序颠倒了: 有时候会发现一个奇怪的现象,那就是为对象添加右浮动以后,显示顺序和原来的顺序颠倒了,下面就结合实例分布分析一下出现这种现象的原因. 实例一: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51texiao.cn/" />

为什么IE6下右浮动的对象换行了

为什么IE6下右浮动的对象换行了:当一个对象右浮动的时候,在IE6浏览器下面,它有可能会换行.先看一段代码实例: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51texiao.cn/" /> <title>蚂蚁部落</title&

css给span加float:right右浮动后内容换行下移

转自:https://www.jb51.net/css/67309.html 在div css布局中 当span标签右浮动时会产生换行狭义的现象 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns= "http://www

右浮动div换行现象的原因

右浮动div换行现象的原因:当然右浮动出现div换行的原因是多种多样的,下面就介绍一个初学者比较容易出现的一个错误.代码实例: <!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</

li元素右浮动会出现换行

li元素右浮动会出现换行:一般情况下想让块级元素在一行显示,可以为元素施加浮动,但是有时候表现却并非如人愿,会出现换行的情况.看如下代码: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂

两列布局——只用右浮动

通过这个实验我明白了一个知识点,做左右结构的时候,不用把左边的写上左浮动,只需要把有浮动的块放到最前边,并设置有浮动,左边的放在有浮动的下边而且不用管,这样,父元素也不用清楚浮动,左边的元素也不用左浮动,一切就依旧会和自己做左右布局的老方法一样的效果.切记,结构上,把有浮动的元素放到前边,并设置右浮动. 为了试验不用清楚浮动,我把clearfix的相关代码注销了. 上代码: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta c