html - :focus on class doesn't work

标签 html css hover focus

我希望类在选择后显示不同的颜色。为什么它只是回到非 active 颜色?我该怎么做才能让它专注于我的类(class)?

我在这个论坛上尝试了很多东西,但似乎没有任何效果。我很快就需要它来上学。

.Auswahl {
  outline: none;
  background-color: #F6F6F6;
  border: none;
  margin-right: -4px;
  float: left;
  -webkit-transition: background-color 0.2s linear;
  -moz-transition: background-color 0.2s linear;
  -o-transition: background-color 0.2s linear;
  transition: background-color 0.2s linear;
}
.Auswahl:hover {
  background-color: #FF0004;
}
.Auswahl:active {
  background-color: #00FF2B;
}
.Auswahl:focus {
  background-color: #7100FF;
}
<div class="Auswahl">
  <h1>Sparkasse</h1>
  <br>Vorteile
  <br>Nachteile
</div>

最佳答案

The :focus pseudo-class applies while an element has the focus (accepts keyboard events or other forms of text input).

更多信息 here

像这样更改您的 HTML:

.Auswahl {
  outline: none;
  background-color: #F6F6F6;
  border: none;
  margin-right: -4px;
  float: left;
  -webkit-transition: background-color 0.2s linear;
  -moz-transition: background-color 0.2s linear;
  -o-transition: background-color 0.2s linear;
  transition: background-color 0.2s linear;
}
.Auswahl:hover {
  background-color: #FF0004;
}
.Auswahl:focus {
  background-color: #7100FF;
}
.Auswahl:active {
  background-color: #00FF2B;
}
<button class="Auswahl">
  <h1>Sparkasse</h1>
  <br>Vorteile
  <br>Nachteile
</button>

关于html - :focus on class doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28049009/

相关文章:

ios - 桌面电脑和 iPad 上的悬停行为

javascript - chart.js 动画结束回调

html - 列表样式未在 IE 中设置为无

jquery - 使用 Sweet Alert 和 jquery 进行表单输入

jquery - Accordion 菜单停止添加 href 链接

css - child 在悬停时与 parent 的 sibling 重叠

html - 添加图像后,Div 的高度会立即扩展

html - 非等高元素的基础 6 block 网格

css - 资源解释为样式表但使用 MIME 类型 text/html 传输

jquery - 通过 ScrollMagic 使用固定和补间