【问题标题】:CSS Animation Line Grow on Hover [closed]CSS动画线在悬停时增长[关闭]
【发布时间】:2018-11-04 05:53:48
【问题描述】:
我有一个悬停时需要动画的按钮。下图显示了“阅读更多”一词,我希望右侧的黄线在悬停时扩大到比其当前大小多 %50 左右。
<a href="#" class="read_more">Read More </a> .read_more { font-family: "Gotham SSm A", "Gotham SSm B"; font-size: 20px; color: #002c77; letter-spacing: 0; text-align: center; line-height: 28px; font-weight: bold; text-transform: uppercase; } .read_more::after { content: "\2014"; color: #fcd450; }
【问题讨论】:
标签:
css
animation
hover
keyframe
【解决方案1】:
见下文。希望这会有所帮助
.read_more {
font-family: "Gotham SSm A", "Gotham SSm B";
font-size: 20px;
color: #002c77;
letter-spacing: 0;
text-align: center;
line-height: 28px;
font-weight: bold;
text-transform: uppercase;
}
div {
position: relative;
display: inline-block;
}
div:after {
content: "";
height: 3px;
width: 20px;
background-color: red;
position: absolute;
right: -20px;
top: 50%;
transform: translateY(-50%);
}
div:hover:after {
width: 30px;
right: -30px;
}
<div><a href="#" class="read_more">Read More</a></div>
【解决方案2】:
伪代码,因为它看起来不像你有任何东西,但是
.line {
width: 100px;
transition: width .5s ease-in-out;
}
.line:hover {
width: 150px;
}
【讨论】:
-
我应该添加我的代码,抱歉。 阅读更多 .read_more { font-family: "Gotham SSm A", "Gotham SSm B";字体大小:20px;颜色:#002c77;字母间距:0;文本对齐:居中;行高:28px;字体粗细:粗体;文本转换:大写; } .read_more::after { 内容:“\2014”;颜色:#fcd450; }
-
【解决方案3】:
根据您自己的代码,我认为这实现了您所追求的! :)
一旦你将它粘贴到你自己的项目中,字体等等就会起作用。
.read_more {
font-family: "Gotham SSm A", "Gotham SSm B";
font-size: 20px;
color: #002c77;
letter-spacing: 0;
text-align: center;
line-height: 28px;
font-weight: bold;
text-transform: uppercase;
}
.read_more:after {
content: '';
position: relative;
display: inline-block;
width: 20px;
height: 2px;
vertical-align: top;
margin-top: 12px;
background-color: #fcd450;
transition: width 0.3s ease;
}
.read_more:hover:after {
width: 30px;
}
<a href="#" class="read_more">Read More </a>