As I was searching the internet for a button style to use on my register form's button, I came across this awesome animated button code in simple HTML & CSS. I attempted to convert it to styled-components, but I couldn't quite get it to match the original design on CodePen. Can someone help me correct my code to replicate the original look?
HTML :
<div class="wrapper">
<a href="#"><span>Hover Me!</span></a>
</div>
CSS :
.wrapper{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a{
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid #333;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all .35s;
}
a span{
position: relative;
z-index: 2;
}
a:after{
position: absolute;
content: "";
top: 0;
left: 0;
width: 0;
height: 100%;
background: #ff003b;
transition: all .35s;
}
a:hover{
color: #fff;
}
a:hover:after{
width: 100%;
}
My try JSX :
const Button = styled.button`
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid teal;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all 0.35s;
`;
const Span = styled.span`
&:after {
position: absolute;
content: "CREATE";
top: 0;
left: 0;
width: 0;
height: 100%;
background: teal;
transition: all 0.35s;
cursor: pointer;
}
&:hover {
color: white;
}
&:hover:after {
width: 100%;
}
`;
const Register = () => {
return (
<div>
<Button>
<Span>CREATE</Span>
</Button>
</div>
);
};
export default Register;