In my following minimal example I have a div that acts as a button. It has a tabindex, so if I use the tab key and get to the element, the style of the class .with-focus
is applied. So far so good.
But I get the style of the class .with-focus
as well when clicking with the mouse on the button. And this is what I do NOT want. Is it possible to avoid?
.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>