[英]How to animate underline on text on hover AND keep the line on mouse out
I've seen a lot of question and tutorials on how to animate a line, but they don't seem to fix my issue.我看过很多关于如何为线条设置动画的问题和教程,但它们似乎并没有解决我的问题。 I have a text with an already underline, so I want the user to hover under on the div that contains the text and have the line animate left to right but keep the line afterwards.我有一个已经有下划线的文本,所以我希望用户将鼠标悬停在包含文本的 div 上,并使该行从左到右动画,但之后保留该行。
This is the code that I have at the moment but its very glitch and the border bottom and :after dont work well together because they are at different height这是我目前拥有的代码,但它的小故障和边框底部和 :after 不能很好地协同工作,因为它们处于不同的高度
.cta-text{
color: #2980FF;
border-bottom: 3px solid #2980FF;
transition: width .2s;
&:hover{
border-bottom: none;
}
&::after {
content: '';
width: 0;
height: 3px;
display: block;
background: #2980FF;
}
&:hover::after {
width: 100%;
margin-top: -2px;
transition: width .3s;
}
}
Here's a codepen example https://codepen.io/godhandkiller/pen/jOrVjdq这是一个代码笔示例https://codepen.io/godhandkiller/pen/jOrVjdq
Use @keyframes to change/pause animation.使用@keyframes更改/暂停动画。
@keyframes hover { 0% { // normal styles } 100% { // hover styles } } .class { animation-name: hover; animation-duration: 1ms; animation-fill-mode: backwards; animation-play-state: paused; } .class:active, .class:focus, .class:hover { //hover style you define }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.