2011-05-03 144 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 {...} 
相关问题