2011-04-13 15 views
3

我是個初學者,所以如果你知道其他的解決辦法告訴我;) 我想讓菜單上我的網站是這樣的:IE和:首個類型

link/link/link/link/link 

菜單中所以這裏是我做了什麼:

li:before { 
    content: "/"; 
} 

li:first-of-type { 
    color: #FFF; /* I've made first "/" same color as background, so we don't see it */ 
} 

有一些填充的標籤,所以它看起來不錯,但我想使它簡單爲你讀。

在大多數瀏覽器中,它看起來很好,但當然舊的Internet Explorer不支持:first-of-type標籤。我該如何解決這個問題,所以用戶看不到第一個斜線?

回答

14
li:first-child:before { 
    content: ''; 
} 

:first-child僞類由IE7及更高版本支持。

請注意,IE7支持:first-childwith some caveats),但直到IE9支持它的朋友:last-child

另外,要隱藏添加了content屬性的內容,請不要更改顏色以匹配背景顏色,因爲這就是我所稱的醜陋的破解

取而代之,將其content設置爲空字符串,如上例所示。

+5

+1 ...因爲':first-child'是CSS2的一部分,而':first-of-type'和':last-child'是CSS3的一部分。 – BoltClock 2011-04-13 11:08:34

+0

@alex:嘿,典型。 – 2011-04-13 11:08:38

+0

太快了,太簡單了......而且我無法在互聯網上找到它)非常感謝你 – smogg 2011-04-13 11:09:14