ie下z-index问题的解决方法
2014-06-06 15:07
239 查看
最近做了一个项目,用到多步骤表单,但是表单的进度条在ie下确显示不正常,如下图
下面是进度条的代码:
可以看见灰色的连接线(li:after)覆盖了li中的数字,但是明明已经设置了z-index为-1了啊,为什么没有用呢?原因是在ie中z-index仅仅作用于父元素中,li没有设置z-index在ie中默认为0,那么所有的li的z-index都是一样的,因此后一个li中的所有内容都会覆盖前一个li,所以后一个li的连接线覆盖了前一个li的数字.因此这种情况下我们需要给父元素设置不同的z-index.
解决办法如下:
关于这个问题的更详细的解释请看:
http://www.davidtong.me/z-index-misconceptions-bugs-fixes/
下面是进度条的代码:
<span style="font-size:14px;"><ul id="progressbar"> <span> </span><li class="active">View Info</li> <li>Filters</li> <li>Column Settings</li> <li>Finish</li> </ul></span>
<span style="font-size:14px;">#progressbar li { list-style-type: none; text-transform: uppercase; font-size: 9px; float: left; position: relative; text-align:center; counter-increment: step; } #progressbar li:before { content: counter(step); width: 20px; line-height: 20px; display: block; font-size: 10px; color: #333; background: #eee; border-radius: 3px; margin: 0 auto 5px auto; text-align:center; } /*progressbar connectors*/ #progressbar li:after { content: ''; width: 100%; height: 2px; background: #eee; position: absolute; left: -50%; top: 9px; z-index: -1; /*put it behind the numbers*/ } #progressbar li:first-child:after { /*connector not needed before the first step*/ content: none; } /*marking active/completed steps green*/ /*The number of the step and the connector before it = green*/ #progressbar li.active:before, #progressbar li.active:after{ background: #27AE60; color: #fff; }
可以看见灰色的连接线(li:after)覆盖了li中的数字,但是明明已经设置了z-index为-1了啊,为什么没有用呢?原因是在ie中z-index仅仅作用于父元素中,li没有设置z-index在ie中默认为0,那么所有的li的z-index都是一样的,因此后一个li中的所有内容都会覆盖前一个li,所以后一个li的连接线覆盖了前一个li的数字.因此这种情况下我们需要给父元素设置不同的z-index.
解决办法如下:
$('#progressbar li').each(function(idx,li){ $(li).css('z-index',100-idx); });这样,四个li的z-index分别为100,99,98,97,就不会覆盖到前面的li了.
关于这个问题的更详细的解释请看:
http://www.davidtong.me/z-index-misconceptions-bugs-fixes/
相关文章推荐
- 进一步解析ie环境下z-index问题解决方法
- ie7下z-index失效问题解决方法
- ie7下z-index失效问题解决方法(详细分析)
- ie7下z-index失效问题解决方法(详细分析)
- ie7下z-index失效问题解决方法(详细分析)
- ie7下z-index失效问题解决方法(详细分析)
- IE7下z-index失效问题及解决方法
- ie7下z-index失效问题解决方法(详细分析)
- ie7下z-index失效问题解决方法(详细分析)
- IE问题解决方法汇总
- select挡住div的解决方法以及frame问题和IE、FLASH与实用代码
- vs2008与IIS 7.0使用在vista上时出现的问题及解决方法(Internet Explorer 无法显示该页面)(VS2008: IE Cannot Display Web Page)
- 【IE信息栏问题】本地html文件js被IE阻止的一些解决方法
- 关于Firefox和IE下的CSS表现的几个问题和解决方法
- IE被某些网站恶意代码修改的问题解决方法心得
- 用IE删除软件删除IE出现问题解决方法
- vista sp1 使用迅雷后ie问题(解决方法)
- Asp.net解决无效的 CurrentPageIndex 值.它必须大于等于 0 且小于 PageCount!的问题方法
- 解决IE不能主动识别UTF-8编码的问题的方法