Home Web Front-end CSS Tutorial Creating a Shooting Star Border Animation with Tailwind CSS

Creating a Shooting Star Border Animation with Tailwind CSS

Sep 05, 2024 am 06:46 AM

Creating a Shooting Star Border Animation with Tailwind CSS

In this blog post, we'll create a captivating "shooting star" border animation using Tailwind CSS. This effect gives a glowing, animated border to an input field that can catch the user's attention—perfect for call-to-action sections like email sign-ups or important notifications.

Demo

Before diving into the code, you can check out the live demo of the effect here: View in Tailwind Playground.

The Concept

The animation is achieved using Tailwind CSS's utility classes and pseudo-elements. We'll use Tailwind's after pseudo-class to create a conic gradient animation that spins around the input field, giving the illusion of a shooting star tracing the border.

HTML and Tailwind CSS Setup

Below is the HTML structure and Tailwind CSS classes needed to create this effect:

<div class="flex h-screen bg-black">
  <div class="z-10 m-auto overflow-hidden p-0.5">
    <div class="after:transparent relative h-14 w-[500px] rounded-md border border-white/50 bg-black after:absolute after:-inset-[1px] after:-z-10 after:h-full after:w-full after:animate-[spin_4s_infinite] after:bg-[conic-gradient(var(--tw-gradient-stops))] after:from-transparent after:from-40% after:via-50% after:to-blue-600 after:to-100%">
      <input type="text" placeholder="Join the waitlist, enter your email.." class="h-full w-full bg-transparent px-4 text-lg text-white placeholder:text-white/40 focus:outline-none" />
    </div>
  </div>
</div>
Copy after login

Breaking Down the Code

Container Setup

  <div class="flex h-screen bg-black">
Copy after login
  • We start by creating a flex container that centers the content both vertically and horizontally with h-screen (full height) and bg-black (black background).

Wrapper for Input Field

  <div class="z-10 m-auto overflow-hidden p-0.5">
Copy after login
  • The input field is wrapped inside a div that has z-10 to ensure it is above the animated border, m-auto to center it within the flex container, and overflow-hidden to contain the animated border within its bounds.

Input Field with Animated Border

  <div class="after:transparent relative h-14 w-[500px] rounded-md border border-white/50 bg-black ...">
Copy after login
  • The main input field is set to a fixed width of 500px and height of 14 Tailwind units.
  • The border-white/50 class adds a semi-transparent border, while rounded-md gives it rounded corners.
  • bg-black sets the background color to black, blending it with the container.

Creating the Animation

  after:absolute after:-inset-[1px] after:-z-10 after:h-full after:w-full after:animate-[spin_4s_infinite] after:bg-[conic-gradient(var(--tw-gradient-stops))] after:from-transparent after:from-40% after:via-50% after:to-blue-600 after:to-100%">
Copy after login
  • The after pseudo-element is used to create the conic gradient that will animate around the border.
  • after:-inset-[1px] slightly expands the gradient beyond the input's border, and after:absolute positions it absolutely to cover the entire input area.
  • after:animate-[spin_4s_infinite] adds a custom spin animation that completes one full rotation every 4 seconds.
  • The after:bg-[conic-gradient...] creates the gradient effect. We use the from-transparent and to-blue-600 classes to define the color stops, giving a fading effect that mimics a shooting star.

Input Field Styling

  <input type="text" placeholder="Join the waitlist, enter your email.." class="h-full w-full bg-transparent px-4 text-lg text-white placeholder:text-white/40 focus:outline-none" />
Copy after login
  • The input itself is transparent (bg-transparent) and takes up the full height and width of its parent.
  • The text-lg class sizes the text, while text-white and placeholder:text-white/40 ensure that the text and placeholder are visible against the dark background.
  • Finally, focus:outline-none removes the default focus outline to maintain the custom styling.

Conclusion

With just a few lines of Tailwind CSS and the power of pseudo-elements, you can create eye-catching effects like this shooting star border animation. This effect is not only aesthetically pleasing but also easy to implement and customize for your own projects. Feel free to tweak the colors, timing, and other properties to fit your design needs!

Happy coding!

Cover Photo by Juskteez Vu on Unsplash

The above is the detailed content of Creating a Shooting Star Border Animation with Tailwind 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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

How to Create an Animated Countdown Timer With HTML, CSS and JavaScript How to Create an Animated Countdown Timer With HTML, CSS and JavaScript Apr 11, 2025 am 11:29 AM

Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

HTML Data Attributes Guide HTML Data Attributes Guide Apr 11, 2025 am 11:50 AM

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

How We Created a Static Site That Generates Tartan Patterns in SVG How We Created a Static Site That Generates Tartan Patterns in SVG Apr 09, 2025 am 11:29 AM

Tartan is a patterned cloth that’s typically associated with Scotland, particularly their fashionable kilts. On tartanify.com, we gathered over 5,000 tartan

How to Build Vue Components in a WordPress Theme How to Build Vue Components in a WordPress Theme Apr 11, 2025 am 11:03 AM

The inline-template directive allows us to build rich Vue components as a progressive enhancement over existing WordPress markup.

PHP is A-OK for Templating PHP is A-OK for Templating Apr 11, 2025 am 11:04 AM

PHP templating often gets a bad rap for facilitating subpar code — but that doesn&#039;t have to be the case. Let’s look at how PHP projects can enforce a basic

While You Weren't Looking, CSS Gradients Got Better While You Weren't Looking, CSS Gradients Got Better Apr 11, 2025 am 09:16 AM

One thing that caught my eye on the list of features for Lea Verou&#039;s conic-gradient() polyfill was the last item:

See all articles