Skip to content

Instantly share code, notes, and snippets.

@townivan
Last active November 14, 2018 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save townivan/10a4f9f30880dddecf426e9cb277f79e to your computer and use it in GitHub Desktop.
Save townivan/10a4f9f30880dddecf426e9cb277f79e to your computer and use it in GitHub Desktop.
outline style only for keyboard
<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