带滑动动画按钮的边框渗色问题求助
问题
我正在制作一个带有滑动动画的按钮,该按钮设置了border-radius,并使用伪元素实现动画效果。
以下是标记代码:
<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>
以下是样式代码:
.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); } }
动画速度调至25%的录屏中,可见按钮左右边框存在渗色现象:
已尝试方案
- 调整z-index与边框设置,渗色问题仍存在。
- 使用div替代伪元素实现背景动画。
- 尝试使用
box-shadow,但因动画效果不符未继续。 - 鼠标悬停时缩放前景(黑色层)。
内容的提问来源于stack exchange,提问作者Danish Shakeel
相关产品推荐
相关产品推荐

