【问题标题】:button colour not changing on hover悬停时按钮颜色不变
【发布时间】:2016-07-20 07:15:18
【问题描述】:

我希望按钮中链接的颜色在悬停时为黄色,但它似乎不起作用,因为在悬停时,文本仍然是白色的。

html:

<button class="headerbutton headerbutton-style">
     <a href="#">Learn More</a>
</button>

css:

a, .headerbutton {
    -webkit-transition: all 0.2s ease-in; 
    -moz-transition: all 0.2s ease-in;
    -o-transition: all 0.2s ease-in; 
}

.headerbutton {
    font-family: "Open Sans";
    font-weight: 400;
    font-size: 12pt;
    border-radius: 20px;
    cursor: pointer;
    padding: 15px 25px;
}

.headerbutton-style {
    background-color: #FAD059;
    border: 2px solid white;
}

.headerbutton-style:hover {
    background-color: white;
    color: #FAD05A;
}

.headerbutton a {
    color: white;
    text-decoration: none;
}

.headerbutton a:hover {
    color: #FAD05A;
    text-decoration: none;
}

【问题讨论】:

  • 您的代码工作正常,当我将其复制并粘贴到 jsfiddle 中时(这将是您的工作 - 请阅读 minimal reproducible example)。大概你有更多的 CSS 规则干扰它。

标签: css button text colors hover


【解决方案1】:

改变这条规则

.headerbutton a:hover {
    color: #FAD05A;
    text-decoration: none;
}

到这里

.headerbutton:hover a {
    color: #FAD05A;
    text-decoration: none;
}

然后它将起作用。看到这个http://codepen.io/anon/pen/RaLwEB

【讨论】:

  • 谢谢!我知道这很简单,感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2016-10-30
  • 2020-07-23
  • 1970-01-01
  • 2018-09-28
  • 2020-09-01
  • 1970-01-01
  • 2021-06-12
  • 1970-01-01
相关资源
最近更新 更多