I noticed that making changes to the filter
property on hover causes strange behavior in Safari 16.2 on macOS:
Using -webkit-filter
doesn't help either.
/* problem-relevant CSS */ div{ background: red; filter: grayscale(1); } div:hover{ filter: grayscale(0); } /* some further styling for readability */ div{ display: flex; justify-content:center; color: white; padding:10px; font-size:25px; }
<div>Hover Me</div>
Here’s what it looks like (GIF):
What can be done about this?
P粉4603775402024-04-02 00:29:42
This seems to be a webkit rendering error.
I found several solutions:
transform
without actually transforming anything (e.g. scale(1)
) fixes this somehowtransition:0.05s
will help (despite creating an unwanted transition), any longer transition will also do the trick (if you normally want to put transitions here, you might This problem will never be discovered) Fun fact: Even a shorter transition (i.e. 0.03s
) doesn't solve anything.
/* solution-relevant CSS */ div{ background: red; filter: grayscale(1); } div:hover{ filter: grayscale(0); transform: scale(1); } /* some further styling for readability */ div{ display: flex; justify-content:center; color: white; padding:10px; font-size:25px; }
Hover Me