When you click on a button in the mobile browser emulation, the button remains highlighted.
When you click on a button On the desktop version of the browser, everything works correctly.
How to fix this?
.button-coontainer {
display: flex;
height: 90vh;
justify-content: center;
align-items: center;
}
.btn-link {
display: inline-block;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
text-decoration: none;
cursor: pointer;
transition: background-color 0.3s ease;
-webkit-tap-highlight-color: transparent;
}
.btn-link:hover {
background-color: #0056b3;
}
.btn-link:active {
background-color: #004080;
transform: translateY(2px);
}
<div class="button-coontainer">
<a class="btn-link" style="-webkit-tap-highlight-color: transparent;">
My button
</a>
</div>
2
Answers
This is used for giving the website visitor a visual feedback, in mobile devices it is a useful thing to not remove.
Basically, it is a feature to show the user that the button is clicked, which removing wouldn’t be good.
But if you’re willing to remove it still, you can use this CSS code:
This will help with removing the highlight issue you’re having.
On mobile, it works similarly to hover when the touch starts.
There is a way to adjust it to the viewport size, but It is desirable to show the behavior to the user.