I have the following shimmer effect working very well when used on a p
element but it doesn't work on any div
nor an img
. So, what modifications should I make to make sure the shimmer effect plays on any element.
The snippet is below
.shimmer {
display: inline-block;
color:grey;
background: #acacac -webkit-gradient(linear, 100% 0, 0 0, from(#acacac), color-stop(0.5, #ffffff), to(#acacac));
background-position: -50rem top; /*50px*/
background-repeat: no-repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-webkit-animation-name: shimmer;
-webkit-animation-duration: 2.2s;
-webkit-animation-iteration-count: infinite;
-webkit-background-size: 50rem 100%; /*50px*/
font-size: 90px;
}
@-webkit-keyframes shimmer {
0% {
background-position: -50rem top; /*50px*/
}
70% {
background-position: 12.5rem top; /*200px*/
}
100% {
background-position: 12.5rem top; /*200px*/
}
}
<div>
<p class="shimmer">Shimmering Text</p>
<div>
<img src="https://i.sstatic.net/MeQxk.png" width=100 height=100 alt="Image Should Shimmer.Unfortunately not working "/>
</div>
</div>
<>
icon on it on the question editor) from what I see at first glance it should work fine on most elements but notimg
however there's workarounds for all that. – Angloindianbackground-clip: text
but with your image unfortunately it's not so clean and you're restricted to the box model of its parent container (eg;border-box
,content-box
, etc) but if your background will consistently stay white like the example I can show you how to mimic the same effect, is that all you're looking for? Or are you needing it to clip to the image contents shape? That's trickier. – Angloindian