I am using translateY
to give the button a depth effect using CSS keyframes and then using that keyframe into :hover
pseudo state with the help of the animate
property. But, it’s kind of shifting behind the ::after
element.
Any Possible solutions that could help me achieve the desired animation?
When the button is pressed or hovered (on Desktop) the white part should be pressing in a way that it gets dissolved with the white border.
.container {
display: flex;
align-items: center;
justify-content: center;
}
.abstract-btn {
text-decoration: none;
font-family: 'Poppins', sans-serif;
background: #000000;
color: #fff;
letter-spacing: 2px;
position: relative;
width: 195px;
height: 46px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
}
.abstract-btn::after {
content: '';
display: block;
position: absolute;
height: 46px;
width: 195px;
top: 3px;
left: 3px;
background: #fff;
border: 1px solid #000;
z-index: -1
}
.abstract-btn::before {
content: '';
position: absolute;
right: -5px;
top: 0;
width: 0;
height: 0;
border-top: 25px solid white;
border-right: 30px solid transparent;
transform: rotateY(180deg);
}
.abstract-btn:hover {
animation: pressButton 1s ease both;
}
@keyframes pressButton {
from {
transform: translateZ(0px);
}
to {
transform: translateZ(3px);
}
}
<div class="container">
<a href="#" class="abstract-btn">
Return Home
</a>
</div>
Here, I am using the ::after
to create the white border and ::before
to add the triangle on the top right corner of the button.
2
Answers
I don’t know if it’s that style of button but I made one that looks like what you describe on my Codepen. Let me know if that’s right.
https://codepen.io/ArthurCottey/pen/OJoMgZW
HTML:
CSS:
This can be done with transitions on the
top
andleft
properties of both the.abstract-btn
and.abstract-btn::after
. The.abstract-btn
havingdisplay: flex;
was causing the problem of the::after
showing in front. I changed it todisplay: block;
then wrapped the link text in a span positioned in the center.