I have class that applies a dotted style border property to a text block at runtime. I am trying to find a solution, using CSS, that makes the border move like a gif image.
Is there any way to achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This depends on what exactly you want the animation to look like.
In general, the styles given to you by
border-styleare rendered statically; it’s simply not possible to animate them.Even with CSS3, your options are fairly limited. The best you can do with
border-imageis either with a carefully-crafted animated GIF (again, it would depend on how a browser implementsborder-imagewith animated images), or with a gradient animation — and whichever you choose depends on browser compatibility and how you want your effect to look.Otherwise you can experiment with
::beforeand::afterpseudo-elements to achieve your desired effect.As a word of warning, though, unless you can ensure your animation meets the relevant WCAG guidelines, in particular 2.2.2 and 2.3, I strongly advise against especially going for the animated-GIF look. On top of being dangerous to certain people, a poorly-crafted animation may turn out more annoying than helpful to most — this is what made animated GIFs so infamous back in the day.
In other words, use this technique sparingly, and only when you know it adds to the user experience rather than taking away from it.