Translating HTML/CSS button with animation to Next.js + Tailwind?
Unanswered
Red-billed Tropicbird posted this in #help-forum
Red-billed TropicbirdOP
Hello, I was following some tutorial where we created a rather nice button just with plain HTML and CSS:
This is the relevant CSS code:
<a href="#" class="btn btn-white btn-animated">Discover our tours</a> This is the relevant CSS code:
@keyframes moveInBottom {
0% {
opacity: 0;
transform: translateY(30px);
}
100% {
opacity: 1;
transform: translate(0);
}
}
.btn:link,
.btn:visited {
text-transform: uppercase;
text-decoration: none;
padding: 15px 40px;
display: inline-block;
border-radius: 100px;
transition: all .2s;
position: relative;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 10px 20px rgba(0, 0, 0, .2 green, blue, alpha);
}
.btn:active {
transform: translateY(-1px);
box-shadow: 0 5px 10px rgba(0, 0, 0, .2 green, blue, alpha);
}
.btn-white {
background-color: #fff;
color: #777;
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 100px;
position: absolute;
top: 0;
left: 0;
z-index: -1;
transition: all .4s;
}
.btn-white::after {
background-color: #fff;
}
.btn:hover::after {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
.btn-animated {
animation: moveInBottom .5s ease-out .75s;
animation-fill-mode: backwards;
}1 Reply
Red-billed TropicbirdOP
I was wondering how to make the same, just using Next.js and Tailwind CSS:
My question, is this an idiomatic way of doing it?
// components/AnimatedButton.tsx
import React from 'react';
interface AnimatedButtonProps {
label: string;
href: string;
}
const AnimatedButton: React.FC<AnimatedButtonProps> = ({ label, href }) => {
return (
<a href={href} className="btn btn-white btn-animated">
{label}
</a>
)
}
export default AnimatedButton;
// styles/animations.css
@keyframes moveInBottom {
0% {
opacity: 0;
transform: translateY(30px);
}
100% {
opacity: 1;
transform: translate(0);
}
}
// styles/button.css
@layer components {
.btn {
@apply uppercase no-underline inline-block rounded-full relative transition-all;
padding: 15px 40px;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.btn:active {
transform: translateY(-1px);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
.btn-white {
@apply bg-white text-gray-700;
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 100px;
position: absolute;
top: 0;
left: 0;
z-index: -1;
transition: all .4s;
background-color: #fff;
}
.btn:hover::after {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
.btn-animated {
animation: moveInBottom .5s ease-out .75s;
animation-fill-mode: backwards;
}
}
// tailwind.config.js
module.exports = {
// other configurations
content: [
// other content configurations
'./styles/**/*.css',
],
}My question, is this an idiomatic way of doing it?