html - 单击 div 时避免 :focus 样式(仅在 tab 键上)
问题描述
在下面的最小示例中,我有一个 div 作为按钮。它有一个 tabindex,所以如果我使用 tab 键并进入元素,.with-focus
就会应用类的样式。到目前为止,一切都很好。
.with-focus
但是当用鼠标点击按钮时,我也得到了类的风格。这就是我不想要的。有没有可能避免?
.with-focus[tabindex]:focus {
outline: 5px solid green;
}
.btn {
background-color: #eee;
border: 1px solid #ddd;
cursor: pointer;
height: 50px;
text-align: center;
width: 200px;
}
<div class="btn with-focus" tabindex="0" onclick="console.log('clicked')">
Button
</div>
解决方案
推荐阅读
- sql - find views and stored procedures that reference specific field (MS SQL)
- java - 在菜单中重复 for 循环
- android - 如何检查滚动视图的可见百分比?
- android - 未调用 Android GcmListenerService onMessageReceived() 方法
- c - C逐行读取文件到动态数组失败但使用静态数组它可以工作吗?
- android - Recyclerview 不显示第一次项目
- elasticsearch - grok 解析数据的重复字段值
- java - SMBJ:如何打印特定子文件夹中的所有文件
- eclipse - 为我的 Xtext 项目执行“Eclipse 应用程序”运行配置时发出 SIGSEGV 信号
- python - 填写文本框并单击搜索按钮 - 使用 selenium 进行网络抓取