2012-01-13 79 views
1

我目前在使用IE浏览器时遇到了z-index问题。Internet Explorer中的图像上的文本

我有一个div,这个div中的图像和这个图像上的一些文字。

这里是我的HTML代码:

<section id="content_right"> 

        <div class="mini_bloc_image"> 
         <img alt="Camionnette VCI" src="img/mini_reparation_site_nb.png" /> 
         <span><a href="#">R&eacute;paration sur site</a></span> 
         <span>Nous nous d&eacute;pla&ccedil;ons</span> 
        </div> 

和CSS:

#content_right { 
width: 230px; 
height: 484px; 
float: right; 
} 

.mini_bloc_image { 
height: 148px; 
margin-bottom: 20px; 
position: relative; 
} 

.mini_bloc_image > img { 
position: absolute; 
} 

.mini_bloc_image > span:first-of-type { 
display: block; 
position: absolute; 
top: 95px; 
left: 0px; 
font-size: 1.1em; 
background-color: #ffffff; 
padding: 4px 5px 4px 5px; 
} 

.mini_bloc_image > span:last-of-type { 
display: block; 
top: 95px; 
left: 0px; 
position: absolute; 
left: 50px; 
top: 125px; 
color: #ffffff; 
font-size: 1.1em; 
font-family: 'Marck Script', cursive; 
} 

IE不明白我的文字必须在图像...

我发现了一些像这样的解决方案http://www.adrenatie.com/z-index-et-ie6/http://systembash.com/content/css-z-index-internet-explorer/但它不起作用。

有人可以帮我吗?

+0

你是否特意提到IE6? – vcsjones 2012-01-13 15:02:30

+0

你真的需要:第一类型和最后一类型吗? – 2012-01-13 15:19:25

+0

我想是的,因为他们没有相同的字体和服饰。 – Greg 2012-01-13 15:37:25

回答

2

问题是你正在处理span s,默认情况下它们是内联渲染的。如果使用display:block,z-索引将被用于:

.mini_bloc_image > span:first-of-type { 
display: block; 
position: absolute; 
z-index: 10; 
font-size: 1.1em; 
background-color: #ffffff; 
padding: 4px 5px 4px 5px; 
margin-top: 95px; 
} 

.mini_bloc_image > span:last-of-type { 
display: block; 
position: absolute; 
z-index: 10; 
color: #ffffff; 
font-size: 1.1em; 
font-family: 'Marck Script', cursive; 
margin-left: 30%; 
margin-top: 125px; 
} 

更多关于内联元素和定位,见this article

+0

@Greg另外请注意,IE有一个“错误”,其中z索引堆栈将重置。我不认为这是你遇到的问题,Prutswonder的解决方案看起来是正确的。但是,如果您尝试了z-index问题,那么也可能是父元素没有z-index,并且子元素z-index不会覆盖DOM树上更高的元素。这经常发生在下拉菜单中,我相信这是一个IE 6,7或更多的问题。我相信IE 9没有这个问题。就像旁注一样。 – jmbertucci 2012-01-13 15:13:09

+0

为了记录,在这种情况下,您不需要z-index,因为跨度位于HTML和DOM树中的图像之后。作为一个经验法则,如果定位不遵循DOM树的流程,则只需要篡改z-index。 – Prutswonder 2012-01-13 15:21:43

+0

谢谢你的回答。我试过了,我也试过用div替换我的跨度,但它没有奏效。我的文字总是在我的图片下。感谢这篇不错的文章。 [编辑:我刚刚阅读Fozzyuw的评论,我尝试了一些] – Greg 2012-01-13 15:33:36