【问题标题】:disable css style from first child item in nav bar从导航栏中的第一个子项禁用 CSS 样式
【发布时间】:2023-03-30 15:29:01
【问题描述】:

我有一个带有粘性菜单栏的站点qavalidation.com,我想在其中禁用第一个子元素(“Home”)的 CSS 样式,它应该只是作为普通链接工作,没有悬停颜色应该改变,请帮忙!

【问题讨论】:

    标签: css navbar


    【解决方案1】:

    据我从您的问题中了解到,您需要禁用列表元素的第一个子元素的所有悬停效果。为此,您可以使用以下样式。

    a:first-child:hover {
        all:unset!important;
    }
    

    但支持有限 (https://developer.mozilla.org/en-US/docs/Web/CSS/all)

    或者您可以使用 !important 简单地覆盖悬停时的所有效果。例如,

    a:first-child:hover{
    color: #757575 !important;
    background-color: transparent !important;
    }
    

    Reference

    【讨论】:

    • 使用!important 几乎总是不可取的,只要您放置正确的选择器,也没有必要。在该选择器上使用:first-child 将提高足够的特异性以确保应用新规则。
    • @connexo 是的!同意
    【解决方案2】:

    您可能希望使用 :hover 和 :focus 选择器来控制主页链接在悬停或焦点时显示的颜色。 a:hover { color: whatever color you want; } http://www.w3schools.com/cssref/sel_hover.asp
    http://www.w3schools.com/cssref/sel_focus.asp

    【讨论】:

      【解决方案3】:

      使用:first-child伪类:

      ul li:first-child {
         /*your styles here*/
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-11
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-17
        相关资源
        最近更新 更多