我有一个标签,它显示为块状。在页面加载时,通过CSS动画将其宽度从零增加到包含div的一些百分比(该fiddle包含MWE,但此div中有多个链接,每个链接都有不同的宽度)。当悬停时,我希望它能改变颜色、背景颜色,并使用CSS过渡扩展到div的100%。颜色和背景颜色部分已经可以工作,但似乎忽略了宽度过渡。
代码片段:
注意 - 我已经测试过在鼠标悬停时更改链接高度的效果,它是有效的。只有宽度不起作用。也许这与页面加载时的动画有关。
代码片段:
.home-bar {
text-decoration: none;
background-color: white;
color: #5e0734;
display: block;
-webkit-animation-duration: 1.5s;
-webkit-animation-timing-function: ease-out;
-webkit-animation-fill-mode: forwards;
animation-duration: 1.5s;
animation-fill-mode: forwards;
transition: color, background-color, width 0.2s linear;/*WIDTH IGNORED*/
border: 2px solid #5e0734;
overflow: hidden;
white-space: nowrap;
margin-right: 0;
margin-left: 5px;
margin-top: 0;
margin-bottom: 5px;
padding: 0;
}
.home-bar:hover {
background-color: #5e0734;
color: white;
width: 100%;/*WIDTH IGNORED*/
text-decoration: none;
}
#bar0 {
-webkit-animation-name: grow0;
animation-name: grow0;
}
@keyframes grow0 {
from {
width: 0%;
}
to {
width: 75%;
}
}
<a href="#" id="bar0" class="home-bar">LINK</a>
animation-fill-mode: forwards;
的缘故? - Alex