Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

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.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3545

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T03:43:09+00:00 2024-11-26T03:43:09+00:00

A quick trick to create animated silhouettes in CSS

  • 61k

I want to show you a shortcut to fashion an animated scene with silhouetted figures with very little CSS. It does not requires handcrafting an image in CSS, making a drawing in SVG, or using any JavaScript. File it under creative and maybe frivolous!

You can make something like this kitsch Halloween scene..

The silhouettes in the scene are styled with the same gradient.

You can think of it as a way to make a kind of animated collage!

Let's unpack how this was made.

The trick to make animated silhouettes

An interesting application of CSS masks is that you can use an animated image, image formats such as GIF and WebP, as the source of the mask. The trick is to choose an animated image with a transparent background that has distinct figures as the mask-image. When you give the element a solid background that you have applied the mask to, the element appears as an animation filled with your background style.

Let's make one now. There is a decent selection of these type of animated images on Giphy in the sticker section. I will search for the term “wave”.

'Searching

Then, we style a div as described. I apply background-color:green to turn the wave green!

div{   -webkit-mask-image: url("https://i.giphy.com/media/OzXfHi0efbEeA/giphy.webp");   mask-image: url("https://i.giphy.com/media/OzXfHi0efbEeA/giphy.webp");    -webkit-mask-size: 100% 100%;   mask-size: 100% 100%;    mask-repeat: no-repeat;     /* need to set a background */   background-color:green;      /* need to set dimensions */   width: 20rem;   height: 20rem; } 
Enter fullscreen mode Exit fullscreen mode

You can see the result in the codepen below.

You could use the shorthand mask property to reduce the 3 mask-releated properties to a one-liner if you prefer!

Browser interop issues

Chrome still requires prefixed properties for the effect to work. Chrome also expects -webkit-mask-size to be set, Firefox does not. Interop 2023 is meant to be eradicating these interoperability issues.

Which animated image formats should you use?

I would recommend favouring using more modern image formats over GIF that have much better compression. Some GIFs can be monsters! WebP and AVIF support alpha transparency and animation, the mandatory ingredients, so they are the best options at the moment. WebP has total support across modern browsers and AVIF is making good headway.

Accessibility

It is good practice to use the prefers-reduced-motion media query to reduce or disable animation for people with vestibular motion disorders. Something like this would suffice:

/* Remove the animation to avoid vestibular motion triggers. */ @media (prefers-reduced-motion) {   div{     -webkit-mask-image: none;     mask-image: none;      /* use a static background instead */     background-image: url("img/static-green-wave.jpg");   } } 
Enter fullscreen mode Exit fullscreen mode

csswebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.