Table of Contents
Steps to follow
Attributes used
:nth-child(n) selector
grammar
CSS animation
Filter properties
Example
in conclusion
Home Web Front-end CSS Tutorial How to create a shooting star animation effect using CSS?

How to create a shooting star animation effect using CSS?

Sep 05, 2023 am 09:33 AM

How to create a shooting star animation effect using CSS?

Meteors appear to be the twinkling signs of warmth these little shivers produce as they twinkle across the cold night sky. The shooting star effect is one of the most unique background effects for dark theme websites. The shooting star animation is a great example of a loading screen that can hold your attention for a long time while the rest of the material on the website loads. This effect can be exploited in page loaders and user interfaces.

In this article, we will discuss ways to create a meteor animation effect using CSS. For this we will use various properties of CSS like animation, overflow, filter, transform, nth child property, :before and :after pseudo-selectors.

Steps to follow

The following are the steps to create a shooting star animation effect -

Step 1 - Create the basic design of the star using HTML. Create one partial element for the sky and nine

elements for the stars.

Step 2 - To make the star fall at 45 degrees, use the Transform property of the Section element.

Step 3 - Align the p elements according to your requirements.

Step 4 - Make a donut-shaped ball using properties such as position and fill properties. To give them a circular shape, use the border-radius property.

Step 5 - Use :before and :after pseudo-selectors to specify before and after for the stars Effect

Step 6 - Use the nth sub-property to add animation effects to the stars. Specifies the position of each nth child.

Step 7 - Using @keyframes, specify the width of the star's head and tail. Use @-webkit-keyframes to create shooting effects.

Attributes used

We used the following CSS properties -

:nth-child(n) selector

:nth-child(n) is a CSS pseudo-class selector used to match elements based on their position within a sibling group. It matches all elements of the nth child element. n can be a number, keyword, or any formula.

grammar

element :nth-child(n){
   Css declarations;
}
Copy after login

The parameter "n" in brackets indicates the pattern of selecting or matching elements. It may be an even or odd function sign.

Odd values ​​represent items with odd positions in the series, such as 1, 3, 5, etc. Likewise, even values ​​represent items with an even number in the series, such as 2, 4, 6, and so on.

CSS animation

The animation property of CSS allows us to change various style properties of an element within a certain time interval, thereby giving it an animation effect.

@keyframes Used to specify exactly what happens in the animation for a given duration. This is done by declaring CSS properties for certain "frames" during the animation, with percentages ranging from 0% (start of animation) to 100% (end of animation).

Filter properties

It enables developers to add visual effects such as opacity, blur, and saturation to HTML elements.

grammar

filter: none | blur()| drop-shadow() | invert() | opacity() | saturate() | sepia() | url() | brightness()| contrast();
Copy after login

Background - It allows us to add visual effects to HTML elements in the background.

Box-shadow - It enables us to add shadow to HTML elements.

Transform - This property allows us to add a 2D or 3D transform to the element. It allows you to transform, rotate, scale, move, skew, etc. elements.

Example

<!DOCTYPE html>
<html>
<head>
   <title> Shooting Star Animation Effect </title>
   <style>
      *{
         margin: 0;
         padding: 0;
         box-sizing: border-box;
      }
      body{
         overflow: hidden;
      }
      div{
         position: absolute;
         top: 0;
         left: 0;
         background: #000;
         background-position-x: center;
         background-size: cover;
         width: 100%;
         height: 100vh;
         animation: background 68s linear infinite;
      }
      @keyframes background {
         0%{ transform:scale(1);}
         55%{ transform:scale(1.3);}
         100%{ transform: scale(1);}
      }
      span{
         position: absolute;
         left: 50%;
         top: 45%;
         width: 5px;
         height: 5px;
         background: white;
         border-radius: 50%;
         box-shadow: 0 1px 0 5px rgba(254, 254, 255, 0.2), 0 1px 0 7px rgba(245, 254, 255, 0.1), 0 1px 21px rgba(253, 253, 245, 1) ;
         animation: anim 3s ease-in-out infinite;
      }
      span::before{
         content: '';
         width: 290px;
         height: 2px;
         position: absolute;
         top: 53%;
         transform: translateY(-45%);
         background: linear-gradient(90deg, rgba(255, 255, 255, 1), transparent);
      }
      @keyframes anim {
         0%{ transform: rotate(325deg) translateX(0); opacity: 1; }
         40%{ opacity: 0.8; }
         70%{ opacity: 1; }
         100%{ transform: rotate(325deg) translateX(-1400px); opacity: 0; }
      }
      span:nth-child(1){
         top: 0;
         right: 0;
         left: inherit;
         animation-delay: 0 ;
         animation-duration: 1s;
      }
      span:nth-child(2){
         top: 0;
         right: 70px;
         left: inherit;
         animation-delay: 0.3s;
         animation-duration: 4s;
      }
      span:nth-child(3){
         top: 70px;
         right: 0px;
         left: inherit;
         animation-delay: 0.3s ;
         animation-duration: 3s;
      }
      span:nth-child(4){
         top: 0;
         right: 170px;
         left: initial;
         animation-delay: 0.7s;
         animation-duration: 3s;
      }
   </style>
</head>
<body>
   <div>
      <span> </span>
      <span> </span>
      <span> </span>
      <span> </span>
      <span> </span>
      <span> </span>
   </div>
</body>
</html>
Copy after login

in conclusion

In this article, we learned how to create a shooting star effect using CSS. Since web design has improved significantly, online animation is an important tool that website builders use to attract a larger audience. Most people try to use it more often, not just to fill the page but to demonstrate how the page should be read. Animations are used to show form errors, click locations, increase conversion rates, and more.

Animations often grab the user's attention, which is why they are used. Additionally, animations can be used to divert users’ attention while content is loading, giving the impression that it is loading faster and allowing them to immediately observe movement or progress.

The above is the detailed content of How to create a shooting star animation effect using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Let's use (X, X, X, X) for talking about specificity Let's use (X, X, X, X) for talking about specificity Mar 24, 2025 am 10:37 AM

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

See all articles