html - 单击后如何禁用悬停效果?
问题描述
我想要一个 CSS 代码,看起来像这样
div:hover {
some hover effect
}
div:onclick{
some on click event
disable hover
}
这样做的目的是在我只关注一个元素后禁用所有元素的悬停。
解决方案
您可以使用:active
伪类。
button {
cursor:pointer;
outline:none;
border:none;
}
button:hover {
background:#ff9900;
}
button:active {
background:red;
}
<button>Submit</button>
如果您希望在按下按钮后保持样式,请使用:focus
button {
cursor:pointer;
outline:none;
border:none;
}
button:hover {
background:#ff9900;
}
button:focus {
background:red;
}
<button>Submit</button>
推荐阅读
- location - 使用带有 bukkit 的非实心块获取两个位置之间的距离
- bash - 有没有更好的方法来为每个 case 语句重复调用函数
- phpmailer - 如何强制 PhpMailer 5.2 使用 TLS 1.2
- c++ - 矩阵与线程问题的乘法
- anylogic - 3 波 Covid 的系统动力学 SEIR 感染曲线
- .net-core - Blazor 如何在没有提交按钮的情况下提交表单
- sql - 统计客户端 SQL 的数量
- visual-studio - 如何在 SSAS 表格模型中调试 DAX 公式?
- r - 为 plotreg 变量标签添加上标和下标
- postgresql - 在 PostgreSQL 中对列具有特定值的表添加非空约束