2011-05-03 151 views
2

我有一個用<li> s構建的導航的第一個和最後一個孩子的不同背景圖像。有沒有什麼辦法可以使用li:first-child和li:hover

我也想添加懸停圖片。有什麼方法可以將:first-child:hover加在一起?

#nav li:first-child{ 
background:url(../images/topnavsprite.png); 
background-position: 0px 0px; 
} 

#nav li:first-child:hover{ 
background:url(../images/topnavsprite.png); 
background-position: 0px 0px; 
} 

在此先感謝。

+2

你已經擁有了。可能只需要調整你的背景位置,如果你正在做精靈來獲取懸停或第一個孩子上的圖像的正確部分。 – robx 2011-05-03 17:37:33

回答

3

是的,你已經知道了。

  • #nav li:first-child選擇第一個<li>
  • #nav li:first-child:hover選擇第一<li>當它盤旋

同上,用於last-child。 (在非鏈接元素上支持first-childlast-child:hover的瀏覽器中,因此早期版本的Internet Explorer可能會遇到問題。)

0

以下是對我有用的東西。

li:first-child:hover, li:last-child:hover {...} 
相關問題