Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ How to Make a Stunning CTA Animation with Tailwind CSS

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š How to Make a Stunning CTA Animation with Tailwind CSS


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Live Demo / Download

The Call To Action is the most important element of an interface, as it enables users to turn their intentions into actions, and products to finalize a specific goal (e.g., converting a prospect to a free trial).

In all our Tailwind templates you'll find at least one Call To Action. We designed them in unlimited shapes and styles, with the ultimate goal of creating a connection between products and end users.

Generally, we like to design simple and straightforward CTAs, but for this tutorial (which was inspired by Glide), we decided to create a Call To Action animation using Tailwind CSS.

We are going to build a fake button that triggers multiple animations when you hover over it:

  • Changing the section's color scheme from light to dark.
  • Adding a scrolling effect to the text on the button.
  • Highlighting the button's border with a โ€œshineโ€ effect.

Creating the base structure

Alright, let's start by creating the basic structure for our CTA. We'll use the <section> tag as a container and the <a> tag to make everything clickable.

<section class="relative z-0">
  <div class="w-full max-w-5xl mx-auto px-4 md:px-6 py-48">
    <div class="text-center">
      <a
        class="flex flex-col lg:flex-row space-y-4 lg:space-y-0 lg:space-x-6 items-center justify-center text-3xl sm:text-4xl md:text-5xl font-semibold text-slate-900"
        href="#0"
      >
        <!-- Fake Button -->
        <span>
          <!-- Default content: "Build the UI you need" -->
          <span>Build the UI you need</span>
          <!-- Hover content: "Create beautiful user interfaces" -->
          <span
            class="before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces']"
            aria-hidden="true"
          ></span>
        </span>

        <!-- Text: "with Cruip" -->
        <span>with Cruip</span>
      </a>
    </div>
  </div>
</section>

The setup is pretty simple. The only thing to highlight is that we've used pseudo-attributes before and after for the moving text. This lets us duplicate the text without creating another element.

Changing the section color mode on hover

Before defining the rest of the style, let's see how to change the background color when the mouse hovers over it. We will use the before pseudo-attribute to create an overlay.

<section class="relative z-0">
  <div class="w-full max-w-5xl mx-auto px-4 md:px-6 py-48">
    <div class="text-center">
      <a
        class="flex flex-col lg:flex-row space-y-4 lg:space-y-0 lg:space-x-6 items-center justify-center text-3xl sm:text-4xl md:text-5xl font-semibold text-slate-900 before:absolute before:inset-0 hover:before:bg-slate-900 before:-z-10 before:transition-colors before:duration-500 group"
        href="#0"
      >
        <!-- Fake Button -->
        <span>
          <!-- Default content: "Build the UI you need" -->
          <span class="group-hover:opacity-0 transition-opacity duration-500 ease-in-out">Build the UI you need</span>
          <!-- Hover content: "Create beautiful user interfaces" -->
          <span
            class="before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces']"
            aria-hidden="true"
          ></span>
        </span>

        <!-- Text: "with Cruip" -->
        <span>with Cruip</span>
      </a>
    </div>
  </div>
</section>

Creating the fake button interaction

To make a smooth transition between the default content and the hover content, we'll position the latter absolutely with opacity 0. And with Tailwind's group-hover: modifier, we'll switch the opacities.

<section class="relative z-0">
  <div class="w-full max-w-5xl mx-auto px-4 md:px-6 py-48">
    <div class="text-center">
      <a
        class="flex flex-col lg:flex-row space-y-4 lg:space-y-0 lg:space-x-6 items-center justify-center text-3xl sm:text-4xl md:text-5xl font-semibold text-slate-900 before:absolute before:inset-0 hover:before:bg-slate-900 before:-z-10 before:transition-colors before:duration-500 group"
        href="#0"
      >
        <!-- Fake Button -->
        <span class="relative">
          <!-- Default content: "Build the UI you need" -->
          <span class="group-hover:opacity-0 transition-opacity duration-500 ease-in-out">Build the UI you need</span>
          <!-- Hover content: "Create beautiful user interfaces" -->
          <span
            class="absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity duration-500 before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces']"
            aria-hidden="true"
          ></span>
        </span>

        <!-- Text: "with Cruip" -->
        <span>with Cruip</span>
      </a>
    </div>
  </div>
</section>

Styling the button

Now, let's style the button. First, we'll define the style for the default text. We'll use a bunch of Tailwind utility classes to set padding, background gradients, border gradients, and more.

<!-- Fake Button -->
<span
  class="relative p-0.5 rounded-full bg-slate-200 group-hover:bg-slate-800 transition duration-500 overflow-hidden flex items-center justify-center"
>
  <span class="relative whitespace-nowrap">
    <!-- Default content: "Build the UI you need" -->
    <span
      class="block px-8 py-6 rounded-full bg-gradient-to-r from-slate-200 to-slate-100 z-10 group-hover:opacity-0 transition-opacity duration-500 ease-in-out"
      >Build the UI you need</span
    >
    <!-- Hover content: "Create beautiful user interfaces" -->
    <span
      class="absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity duration-500 before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces']"
      aria-hidden="true"
    ></span>
  </span>
</span>

Once we've got that down, we can move on to styling the โ€œhover contentโ€:

<!-- Fake Button -->
<span
  class="relative p-0.5 rounded-full bg-slate-200 group-hover:bg-slate-800 transition duration-500 overflow-hidden flex items-center justify-center"
>
  <span class="relative whitespace-nowrap">
    <!-- Default content: "Build the UI you need" -->
    <span
      class="block px-8 py-6 rounded-full bg-gradient-to-r from-slate-200 to-slate-100 z-10 group-hover:opacity-0 transition-opacity duration-500 ease-in-out"
      >Build the UI you need</span
    >
    <!-- Hover content: "Create beautiful user interfaces" -->
    <span
      class="absolute inset-0 rounded-full bg-gradient-to-r from-slate-900 to-slate-800 z-10 inline-flex items-center whitespace-nowrap overflow-hidden opacity-0 group-hover:opacity-100 transition-opacity duration-500 before:bg-clip-text before:text-transparent before:bg-gradient-to-r before:from-indigo-500 before:to-indigo-300 after:bg-clip-text after:text-transparent after:bg-gradient-to-r after:from-indigo-500 after:to-indigo-300 before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces'] before:px-2 after:px-2"
      aria-hidden="true"
    ></span>
  </span>
</span>

And finally, we'll add a few more classes to define the style for the last portion of the text:

<span class="group-hover:text-slate-300 transition-colors duration-500 ease-in-out">with Cruip</span>

And that's it! We've created a smooth transition from light to dark mode when you hover over the button, and we've added a cool crossfade effect.

Now we can move on to the most interesting part: creating the text scrolling animation and the button border shine effect.

Creating the text scrolling animation

To create this type of effect, all we need to do is define a custom animation in the Tailwind configuration file. We'll call it infinite-scroll and set it up to scroll from right to left. Here's the code:

tailwind.config = {
  theme: {
    extend: {
      animation: {
        'infinite-scroll': 'infinite-scroll 6s linear infinite',
      },
      keyframes: {
        'infinite-scroll': {
          from: { transform: 'translateX(0)' },
          to: { transform: 'translateX(-100%)' },
        },
      },
    },
  },
};

Once we have that animation set up, we can easily apply it to our pseudo-element by using the class animate-infinite-scroll. Like this:

<!-- Hover content: "Create beautiful user interfaces" -->
<span
  class="absolute inset-0 rounded-full bg-gradient-to-r from-slate-900 to-slate-800 z-10 inline-flex items-center whitespace-nowrap overflow-hidden opacity-0 group-hover:opacity-100 transition-opacity duration-500 before:bg-clip-text before:text-transparent before:bg-gradient-to-r before:from-indigo-500 before:to-indigo-300 after:bg-clip-text after:text-transparent after:bg-gradient-to-r after:from-indigo-500 after:to-indigo-300 before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces'] before:px-2 after:px-2 before:animate-infinite-scroll after:animate-infinite-scroll"
  aria-hidden="true"
></span>

Creating the shine effect

This is the final step to complete our CTA. To make the shine effect, we'll use a linear gradient and apply it to the before pseudo-attribute of the button element. Since this gradient is a bit complex, we'll take advantage of Tailwind's arbitrary values feature to achieve it.

To really make the shine effect pop, we'll also add an infinite rotation to the gradient. We don't need to create a custom animation for this. We can just use Tailwind's animate-spin, and use a custom class to change the default rotation time, just like this: animate-[spin_3s_linear_infinite].

So, here's the updated code:

<section class="relative z-0">
  <div class="w-full max-w-5xl mx-auto px-4 md:px-6 py-48">
    <div class="text-center">
      <a
        class="flex flex-col lg:flex-row space-y-4 lg:space-y-0 lg:space-x-6 items-center justify-center text-3xl sm:text-4xl md:text-5xl font-semibold text-slate-900 before:absolute before:inset-0 hover:before:bg-slate-900 before:-z-10 before:transition-colors before:duration-500 group"
        href="#0"
      >
        <!-- Fake Button -->
        <span
          class="relative p-0.5 rounded-full bg-slate-200 group-hover:bg-slate-800 transition duration-500 overflow-hidden flex items-center justify-center before:opacity-0 group-hover:before:opacity-100 before:absolute before:w-1/2 before:pb-[100%] before:bg-[linear-gradient(90deg,_theme(colors.indigo.500/0)_0%,_theme(colors.indigo.500)_35%,_theme(colors.indigo.200)_50%,_theme(colors.indigo.500)_65%,_theme(colors.indigo.500/0)_100%)] before:animate-[spin_3s_linear_infinite]"
        >
          <span class="relative whitespace-nowrap">
            <!-- Default content: "Build the UI you need" -->
            <span
              class="block px-8 py-6 rounded-full bg-gradient-to-r from-slate-200 to-slate-100 z-10 group-hover:opacity-0 transition-opacity duration-500 ease-in-out"
              >Build the UI you need</span
            >
            <!-- Hover content: "Create beautiful user interfaces" -->
            <span
              class="absolute inset-0 rounded-full bg-gradient-to-r from-slate-900 to-slate-800 z-10 inline-flex items-center whitespace-nowrap overflow-hidden opacity-0 group-hover:opacity-100 transition-opacity duration-500 before:bg-clip-text before:text-transparent before:bg-gradient-to-r before:from-indigo-500 before:to-indigo-300 after:bg-clip-text after:text-transparent after:bg-gradient-to-r after:from-indigo-500 after:to-indigo-300 before:content-['Create_beautiful_user_interfaces'] after:content-['Create_beautiful_user_interfaces'] before:px-2 after:px-2 before:animate-infinite-scroll after:animate-infinite-scroll"
              aria-hidden="true"
            ></span>
          </span>
        </span>

        <!-- Text: "with Cruip" -->
        <span class="group-hover:text-slate-300 transition-colors duration-500 ease-in-out">with Cruip</span>
      </a>
    </div>
  </div>
</section>

Conclusions

With the new arbitrary values feature in version 3, Tailwind CSS has become an incredibly flexible tool. It lets us make complex effects like the one we've shown you without writing a single line of CSS.

If you're hungry for more CSS animations like this, we recommend checking out our Tailwind tutorials. For example, we've got a guide on how to make an animated number counter, as well as one on how to create an infinite horizontal scroll animation.

...



๐Ÿ“Œ How to Make a Stunning CTA Animation with Tailwind CSS


๐Ÿ“ˆ 84.05 Punkte

๐Ÿ“Œ Choosing the Right CSS Approach: Tailwind CSS vs Bootstrap vs Vanillaย CSS


๐Ÿ“ˆ 42.8 Punkte

๐Ÿ“Œ Build Stunning NextJs Portfolioโญ Website using Tailwind-CSS and Framer-motion


๐Ÿ“ˆ 40.28 Punkte

๐Ÿ“Œ โœจ Stunning HTML & CSS Card Animation Tutorial on Hover ๐Ÿ’ป


๐Ÿ“ˆ 39.89 Punkte

๐Ÿ“Œ Creating a Scrolling Logo Animation with Tailwind CSS


๐Ÿ“ˆ 37.9 Punkte

๐Ÿ“Œ Animation -13 : Simple Content Preload CSS Animation


๐Ÿ“ˆ 37.51 Punkte

๐Ÿ“Œ Animation -18 : Pure CSS Gooey Loader Animation


๐Ÿ“ˆ 37.51 Punkte

๐Ÿ“Œ Animation -19 : Simple preloader CSS Animation


๐Ÿ“ˆ 37.51 Punkte

๐Ÿ“Œ Animation -22 : Cube Flipping Loader CSS Animation


๐Ÿ“ˆ 37.51 Punkte

๐Ÿ“Œ Build a Tic Tac Toe Game using HTML, CSS, JavaScript, Tailwind CSS and Canvas Confetti


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Tailwind CSS vs Foundation: A Comparison of CSS Frameworks


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Mojo CSS vs. Tailwind: Choosing the best CSS framework


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Tailwind CSS vs. CSS Frameworks: A Comprehensive Comparison for UI Design


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Creating an animated text gradient with Tailwind CSS (and vanilla CSS)


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Why Tailwind CSS is still better than StyleX and other CSS libraries


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Tailwind CSS tip: Make your site look great on any screen.


๐Ÿ“ˆ 30.72 Punkte

๐Ÿ“Œ Create reusable button Components with React,Typescript , Tailwind and Tailwind-variants


๐Ÿ“ˆ 28.83 Punkte

๐Ÿ“Œ Creating a Multi-Level Sidebar Animation with Tailwind and Framer Motion in React


๐Ÿ“ˆ 28.44 Punkte

๐Ÿ“Œ CSS Grid: Moving From CSS Frameworks To CSS Grid (2018 and beyond)


๐Ÿ“ˆ 28.39 Punkte

๐Ÿ“Œ Stylify CSS: Automagic CSS bundles splitting into CSS layers in Astro.build


๐Ÿ“ˆ 28.39 Punkte

๐Ÿ“Œ A BRIEF REVIEW OF CSS CASCADING, CSS SELECTORS and CSS SPECIFICITY.


๐Ÿ“ˆ 28.39 Punkte

๐Ÿ“Œ Pencil2D Animation - Opensource animation software


๐Ÿ“ˆ 28.05 Punkte

๐Ÿ“Œ Animation -17 : Staggered Stair Loading Animation


๐Ÿ“ˆ 28.05 Punkte

๐Ÿ“Œ Specify how multiple animation effects should composite with `animation-composition`


๐Ÿ“ˆ 28.05 Punkte

๐Ÿ“Œ Rendering( or How to Render) Animation in JSON format with LottieFiles animation in React application


๐Ÿ“ˆ 28.05 Punkte

๐Ÿ“Œ Stunning 3D Text Effect Using HTML Andย CSS


๐Ÿ“ˆ 25.86 Punkte

๐Ÿ“Œ Building Intercom's Inbox Clone Using Tailwind CSS


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Tailwind CSS: Das zeichnet das Utility-First-Framework aus


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Malicious NPM Package Caught Mimicking Material Tailwind CSS Package


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Malicious NPM Package Caught Mimicking Material Tailwind CSS Package


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Tailwind CSS tutorial #22: Line Height


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Bootstrap vs Tailwind CSS


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Webentwicklung: Tailwind CSS hat die treuesten Fans


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ Fixing Class Composition in Tailwind CSS


๐Ÿ“ˆ 23.88 Punkte

๐Ÿ“Œ What is Tailwind CSS | Web Wednesday


๐Ÿ“ˆ 23.88 Punkte











matomo