This component is designed to provide a visually engaging call-to-action button for web applications or websites. It combines text and an arrow icon, enhancing user interaction through animation.
Set up the HTML structure:
div
container with the classes flex
, h-svh
, and w-full
to position the button in the center of the viewport.button
element with the classes group
,overflow-hidden
, rounded-md
, bg-blue-500
, px-4
, py-1.5
, text-sm
, text-white
, and shadow-md
.Add the text and arrow elements:
div
with the classes relative
, flex
, and items-center
to center the text and arrow vertically.div
, add another div
with the classes group-hover:translate-x-20
, transition-all
, and duration-300
to create the text animation. This div will contain the text "Click Me!".div
with the classes absolute
, -left-10
, top-1/2
, -translate-y-1/2
, transition-all
, and duration-300
to create the arrow animation. This div will contain the arrow icon.Add the arrow icon:
4. Style the button and animations:
group-hover:translate-x-20
class to make the text move 20 pixels to the right on hover.group-hover:left-1/2
and group-hover:-translate-x-1/2
classes to make the arrow move to the center of the button on hover.
<div class="flex h-svh w-full items-center justify-center">
<button class="group overflow-hidden rounded-md bg-blue-500 px-4 py-1.5 text-sm text-white shadow-md">
<div class="relative flex items-center justify-center">
<div class="group-hover:translate-x-20 transition-all duration-300 ease-in-out ">Click Me!</div>
<div class="absolute -left-10 top-1/2 -translate-y-1/2 transition-all duration-300 ease-in-out group-hover:left-1/2 group-hover:-translate-x-1/2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-right">
<path d="M7 7h10v10" />
<path d="M7 17 17 7" />
</svg>
</div>
</div>
</button>
</div>