2012-01-13 70 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