Last active
November 14, 2018 02:48
-
-
Save townivan/10a4f9f30880dddecf426e9cb277f79e to your computer and use it in GitHub Desktop.
outline style only for keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Let the document know when the mouse is being used | |
document.body.addEventListener('mousedown', function() { | |
document.body.classList.add('using-mouse'); | |
}); | |
document.body.addEventListener('keydown', function() { | |
document.body.classList.remove('using-mouse'); | |
}); | |
</script> | |
<style> | |
/* The default outline styling, for greatest accessibility. */ | |
/* You can skip this to just use the browser's defaults. */ | |
:focus { | |
outline: #08f auto 2px; | |
} | |
/* When mouse is detected, ALL focused elements have outline removed. */ | |
/* You could apply this selector only to buttons, if you wanted. */ | |
body.using-mouse :focus { | |
outline: none; | |
} | |
</style> | |
Source: | |
https://stackoverflow.com/a/51093815/1735394 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment