html - Is it possible to style just focus on tab at checkboxes?
问题描述
I wonder if it is possible to style just focus on tab (using ↹ to navigate through the page)but not if the user click on the item.
Just like the default behaviour of checkboxes. It gets a blue outline (looks like box-shadow) if I use tab.
Like I want a new red box-shadow/outline on focus by tab but not if the user clicks on the checkbox.
<input id="checkBox" type="checkbox">
解决方案
you can do it by Jquery
document.addEventListener('keydown', function(e) {
if (e.keyCode === 9) {
$('#checkBox').addClass('outline');
}
});
document.addEventListener('click', function(e) {
$('#checkBox').removeClass('outline');
});
.outline{
box-shadow: 2px 2px 2px red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="checkBox" type="checkbox">
OR
this plugin:https://github.com/ten1seven/track-focus
in css:
body[data-whatinput="keyboard"] #checkBox:focus {
box-shadow: 0 0 5px red;
}
推荐阅读
- amazon-web-services - 将 S3 存储桶导出到 Blob 存储
- python - python贪婪匹配中的错误
- javascript - 使用按钮在 UL 中动态编辑 LI
- c# - 如何在不使用 System.IO 的情况下更改文件修改日期
- docusignapi - 当使用 DocuSign API 启动签名过程时,文档完成通知未按预期发送给每个收件人
- angular - ngClass 没有被应用
- python - 在新环境中安装 Keras
- sql-server - 每月自动查询
- java - 在 Netbeans 8.2 上更改 JDK 主页
- prestashop - 我没有进入钩子“ActionProductCreate”