Problem
I am trying to create a button with a sliding animation. The button has a border-radius
and uses pseudo-elements to achieve the effect.
Here is the markup:
<div role="button" class="is-style-rt-primary-accent-button">
<a class="rt-button__link" data-text="HELLO WORLD" href="#" target="_self" rel="noopener">
HELLO WORLD
<div class="rt-button">
<div class="rt-button__circle">
<div class="rt-button__arrow">
<span class="rt-button__line"></span>
<span class="rt-button__pointer"></span>
</div>
</div>
</div>
</a>
</div>
Here are the styles:
.is-style-rt-primary-accent-button {
.rt-button__link {
display: inline-flex;
align-items: center;
justify-content: flex-end;
background: none;
font-weight: 700;
padding: 14px 31px;
position: relative;
font-size: 14px;
line-height: 28px;
overflow: hidden;
transition: 0.3s ease-in-out;
text-transform: uppercase;
border-radius: 64px;
z-index: 1;
color: var(--wp--preset--color--accent-1);
text-decoration: none;
&::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 64px;
background: var(--wp--preset--color--accent-6);
transition: 0.3s ease-in-out;
z-index: -2;
}
&::before {
content: "";
position: absolute;
bottom: 0;
left: -100%;
width: 100%;
height: 100%;
border-radius: 64px;
background: var(--wp--preset--color--secondary);
transition: 0.3s ease-in-out;
z-index: -1;
}
&:hover {
color: var(--wp--preset--color--accent-6);
.rt-button__line {
background: var(--wp--preset--color--accent-6);
}
.rt-button__pointer {
border-left: 0.3125rem solid var(--wp--preset--color--accent-6);
}
.rt-button__arrow {
transform: translateX(10px);
}
&::before {
transform: translateX(100%);
}
}
}
.rt-button__circle {
@media screen and (max-width: 768px) {
background: none;
}
}
.rt-button__arrow {
display: flex;
align-items: center;
margin-left: 1rem;
transition: transform 0.3s ease-in-out;
}
.rt-button__line {
display: inline-block;
width: 0.625rem;
height: 0.125rem;
vertical-align: middle;
background: var(--wp--preset--color--accent-1);
}
.rt-button__pointer {
width: 0;
height: 0;
border-top: 0.3125rem solid transparent;
border-bottom: 0.3125rem solid transparent;
border-left: 0.3125rem solid var(--wp--preset--color--accent-1);
}
}
Here is the recording of the issue with animations slowed down to 25%. Notice that at the X borders, there is a bleed.
What I have tried
- I have tried playing with z-index and borders. The bleed still persists.
- Using a div instead of pseudoelements to handle the background animations.
- Using
box-shadow
but since the animation is different, I did not pursue that option further. - Scaling the foreground (black layer) upon hover.