【问题标题】:Is there any way I can use li:first-child and li:hover有什么办法可以使用 li:first-child 和 li:hover
【发布时间】:2011-08-17 21:55:21
【问题描述】:

我为使用<li>s 构建的导航的第一个子项和最后一个子项设置了不同的背景图像。

我还想添加悬停图像。有什么办法可以将: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;
}

提前致谢。

【问题讨论】:

  • 你已经掌握了。如果您正在制作精灵以在悬停或第一个孩子上获得图像的正确部分,可能只需要调整您的背景位置。

标签: css hover css-selectors


【解决方案1】:

是的,你已经知道了。

  • #nav li:first-child 选择第一个<li>
  • #nav li:first-child:hover 悬停时选择第一个 <li>

last-child 同上。 (在非链接元素上支持 first-childlast-child:hover 的浏览器中,早期版本的 Internet Explorer 可能会遇到问题。)

【讨论】:

    【解决方案2】:

    这对我有用。

    li:first-child:hover, li:last-child:hover {...}
    

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 2017-06-02
      • 2021-11-12
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      • 2015-02-25
      • 2016-01-20
      • 1970-01-01
      相关资源
      最近更新 更多