[英]CSS fade transition, is it possible to have the child elements opacity 1 while only fading the container?
i have an issue, i am doing some CSS transitions that look a lot like http://jsfiddle.net/1ummhm0t/ 我有一个问题,我正在做一些CSS过渡,看起来很像http://jsfiddle.net/1ummhm0t/
The issue is that the text within the container lags, is it possible to have the text opacity 1 as soon as the animation is triggered, and only doing the transition on the container element? 问题是容器中的文本滞后,是否可以在触发动画后立即使文本不透明度为1,并且仅对容器元素进行过渡?
If so, what would i have to do to achieve this? 如果是这样,我应该怎么做才能做到这一点?
HTML: HTML:
<div>
<div class="container">
<a href="#">abc</a>
</div>
<div>
CSS: CSS:
@-webkit-keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
div {
background-color: green;
}
.container {
opacity:0;
visibility:hidden:
display: none;
background: gray;
}
a {
color: white;
}
div:hover .container {
opacity:1;
visibility:visible;
display:block;
-webkit-animation: fadeIn 0.2s;
animation: fadeIn 0.2s;
}
I think you just need to animate the background-color
via the use of transition
and not animation
: http://jsfiddle.net/tekwxs07/ . 我认为您只需要通过使用
transition
而非animation
来设置background-color
的animation
: http : //jsfiddle.net/tekwxs07/ 。
HTML: HTML:
<div class="container">
<a href="#">abc</a>
</div>
CSS: CSS:
.container {
background-color: rgba(60, 60, 60, 0.5);
transition: background-color linear 0.5s;
}
.container a {
color: #fff;
text-decoration: none;
}
.container:hover {
background-color: green;
}
http://jsfiddle.net/f2059cg5/ http://jsfiddle.net/f2059cg5/
Is this what you need? 这是您需要的吗? You should use
background: rgba
instead of opacity
for the animation. 您应该对动画使用
background: rgba
而不是opacity
。
@-webkit-keyframes fadeIn {
from {
background: rgba(128,128,128,0);
}
to {
background: rgba(128,128,128,1);
}
}
@keyframes fadeIn {
from {
background: rgba(128,128,128,0);
}
to {
background: rgba(128,128,128,1);
}
}
div {
background-color: green;
}
.container {
opacity: 0;
visibility: hidden:
display: none;
background: gray;
}
div:hover .container {
opacity: 1;
visibility: visible;
display: block;
-webkit-animation: fadeIn 0.2s;
animation: fadeIn 0.2s;
}
a {
visibility: hidden;
color: white;
}
div:hover a {
visibility: visible;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.