Lädt...


🔧 Creating a Shooting Star Border Animation with Tailwind CSS


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

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>

Breaking Down the Code

Container Setup

  <div class="flex h-screen bg-black">
  • 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">
  • 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 ...">
  • 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%">
  • 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" />
  • 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

...

🔧 Creating a Shooting Star Border Animation with Tailwind CSS


📈 80.98 Punkte
🔧 Programmierung

🔧 Creating a Scrolling Logo Animation with Tailwind CSS


📈 42.55 Punkte
🔧 Programmierung

🔧 Configurare Tailwind CSS: Guida all'Inizializzazione | Setting Up Tailwind CSS: Initialization Guide


📈 40.69 Punkte
🔧 Programmierung

🔧 Creating an animated text gradient with Tailwind CSS (and vanilla CSS)


📈 37.58 Punkte
🔧 Programmierung

🔧 Choosing the Right CSS Approach: Tailwind CSS vs Bootstrap vs Vanilla CSS


📈 36.72 Punkte
🔧 Programmierung

🔧 Awesome Border Animation Effects using CSS


📈 35.6 Punkte
🔧 Programmierung

🔧 Tailwind CSS tutorial #33: Border Radius


📈 34.6 Punkte
🔧 Programmierung

🔧 Animation -22 : Cube Flipping Loader CSS Animation


📈 34.5 Punkte
🔧 Programmierung

🔧 Animation -19 : Simple preloader CSS Animation


📈 34.5 Punkte
🔧 Programmierung

🔧 Animation -18 : Pure CSS Gooey Loader Animation


📈 34.5 Punkte
🔧 Programmierung

🔧 Animation -13 : Simple Content Preload CSS Animation


📈 34.5 Punkte
🔧 Programmierung

🔧 Creating a Multi-Level Sidebar Animation with Tailwind and Framer Motion in React


📈 34.37 Punkte
🔧 Programmierung

🔧 How to create a typewriter effect text animation with Tailwind CSS and JavaScript


📈 33.5 Punkte
🔧 Programmierung

🔧 How to Make a Stunning CTA Animation with Tailwind CSS


📈 33.5 Punkte
🔧 Programmierung

🔧 Introduction of CSS, What is CSS, Why we use CSS and How CSS describe the HTML elements


📈 32.75 Punkte
🔧 Programmierung

🔧 Mastering Tailwind CSS: Overcome Styling Conflicts With Tailwind Merge and clsx


📈 32.51 Punkte
🔧 Programmierung

🔧 Mastering Tailwind CSS: Overcome Styling Conflicts with Tailwind Merge and clsx


📈 32.51 Punkte
🔧 Programmierung

🔧 Material TailWind - combining Material Design and Tailwind CSS


📈 32.51 Punkte
🔧 Programmierung

🔧 Creating a Hand Scanning Animation with HTML and CSS || FREE Source Code


📈 30.39 Punkte
🔧 Programmierung

🔧 Creating a Mesmerizing Moonlit Night Sky Animation with CSS


📈 30.39 Punkte
🔧 Programmierung

🔧 Today's Trending Projects: Creating Earth's Orbital Animation with CSS and More


📈 30.39 Punkte
🔧 Programmierung

🔧 Today's Trending Projects: Creating Earth's Orbital Animation with CSS and More


📈 30.39 Punkte
🔧 Programmierung

🔧 Cursor Animation : Creating Smooth Hover Effects in CSS


📈 30.39 Punkte
🔧 Programmierung

🔧 Tailwind CSS: Creating Custom Animations


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Modern Animated Badge Component with Tailwind CSS


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Tailwind CSS Fade Plugin: My Journey


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Stylish 404 Not Found Page in React with Tailwind CSS


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Responsive Profile Settings UI with Tailwind CSS


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Snackbar using Signals and Tailwind CSS generated with V0


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Table Component in React with Tailwind CSS


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a User Nav bar in Next.js 14 using Shadcn UI and Tailwind CSS


📈 29.4 Punkte
🔧 Programmierung

🔧 Creating a Pricing Table with Range Slider using Tailwind CSS and Alpine.js


📈 29.4 Punkte
🔧 Programmierung

🔧 Enhancing User Experience: Creating Custom Checkboxes with Tailwind CSS and React


📈 29.4 Punkte
🔧 Programmierung

🔧 Tailwind CSS in React - Creating Modal Popup


📈 29.4 Punkte
🔧 Programmierung

🔧 Build a Tic Tac Toe Game using HTML, CSS, JavaScript, Tailwind CSS and Canvas Confetti


📈 28.53 Punkte
🔧 Programmierung

matomo