[英]CSS3 animation not working inside Angular component
Can't for the life of me figure out why this isn't triggering as it's a rather simple thing. 我一辈子都无法弄清楚为什么它没有触发,因为这是一件很简单的事情。 I have an Angular component that simply contains the following:
我有一个仅包含以下内容的Angular组件:
<a href="#services">Click</a>
In the corresponding component's CSS, I have this: 在相应组件的CSS中,我有以下内容:
@keyframes bounce{
0% { transform: translateY(0px); }
50% { transform: translateY(5px); }
100% { transform: translateY(0px); }
}
a{
font-size: 3rem;
margin: 0 auto;
text-decoration: none;
transition: all 0.2s;
animation: bounce 1.5s infinite;
}
Using Chrome Dev tools I can see that it outputs the following in a style tag: 使用Chrome Dev工具,我可以看到它在样式标签中输出以下内容:
@-webkit-keyframes bounce{
0% { -webkit-transform: translateY(0px); transform: translateY(0px); }
50% { -webkit-transform: translateY(5px); transform: translateY(5px); }
100% { -webkit-transform: translateY(0px); transform: translateY(0px); }
}
@keyframes bounce{
0% { -webkit-transform: translateY(0px); transform: translateY(0px); }
50% { -webkit-transform: translateY(5px); transform: translateY(5px); }
100% { -webkit-transform: translateY(0px); transform: translateY(0px); }
}
a[_ngcontent-c3]{
font-size: 3rem;
margin: 0 auto;
text-decoration: none;
transition: all 0.2s;
-webkit-animation: bounce 1.5s infinite;
animation: bounce 1.5s infinite;
}
Everything appears to be pointing to the correct element, but the animation isn't working at all. 一切似乎都指向正确的元素,但是动画根本不起作用。 Any thoughts?
有什么想法吗?
It's rather a guess without seeing which other styles may be applied in your component, but you cannot add CSS animations to inline
elements. 这是一个猜测,而没有看到您的组件中可以应用哪些其他样式,但是您不能将CSS动画添加到
inline
元素中。 If you add display: inline-block
or position: absolute
to the <a>
tag, it will work: 如果在
<a>
标签上添加display: inline-block
或position: absolute
,它将起作用:
@-webkit-keyframes bounce{ 0% { -webkit-transform: translateY(0px); transform: translateY(0px); } 50% { -webkit-transform: translateY(5px); transform: translateY(5px); } 100% { -webkit-transform: translateY(0px); transform: translateY(0px); } } @keyframes bounce{ 0% { -webkit-transform: translateY(0px); transform: translateY(0px); } 50% { -webkit-transform: translateY(5px); transform: translateY(5px); } 100% { -webkit-transform: translateY(0px); transform: translateY(0px); } } a[_ngcontent-c3]{ font-size: 3rem; margin: 0 auto; text-decoration: none; transition: all 0.2s; -webkit-animation: bounce 1.5s infinite; animation: bounce 1.5s infinite; } a.inline-block { display: inline-block; }
<a href="#services" _ngcontent-c3>Click</a> <= not working | working with <code>display: inline-block;</code> => <a href="#services" _ngcontent-c3 class="inline-block">Click</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.