Is there any way I can use li:first-child and li:hover
I have a different background image for the first and last child of a navigation built with <开发者_C百科;li>
s.
I also want to add hover image. Is there any way I can add :first-child
and :hover
together?
#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;
}
Thanks in advance.
Yeah, you’ve got it already.
#nav li:first-child
selects the first<li>
#nav li:first-child:hover
selects the first<li>
when it’s hovered
Ditto for last-child
. (In browsers that support first-child
, last-child
, and :hover
on elements that aren’t links, so earlier versions of Internet Explorer may well have trouble.)
Here's what works for me.
li:first-child:hover, li:last-child:hover {...}
精彩评论