I’ve styled the focus state for my webpage to my liking. But now it stays on the buttons/links even when I’m done clicking them. I have to click the blank spaces to make it go away. I only want the focus state to be visible when we use TAB key for shifting focus, and(optional) when the buttons are clicked. How can I do that? Do I need to write some JavaScript for that? Basically I want the focus state to behave in a default way, the way it did before I styled it.
JavaScript
x
9
1
*:focus {
2
outline: none;
3
box-shadow: 0 0 0 0.5rem rgba(61, 112, 46, 0.5);
4
}
5
6
.cta *:focus {
7
box-shadow: 0 0 0 0.5rem rgba(255, 255, 255, 0.5);
8
}
9
Advertisement
Answer
try using this css selector instead of *:focus
JavaScript
1
6
1
*:focus-visible{
2
outline: none;
3
box-shadow: 0 0 0 0.5rem rgba(61, 112, 46, 0.5);
4
5
}
6