gpt4 book ai didi

html - CSS 动画行为

转载 作者:太空宇宙 更新时间:2023-11-04 01:15:21 26 4
gpt4 key购买 nike

我在这里得到了这个示例,是否可以让“p”的 div 内部不是动画,而是 div 容器动画?

div {
width: 100px;
height: 100px;
background-color: red;
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
-webkit-animation-duration: 4s; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 4s;
}

div p {
position: absolute;
top: 25px;
}

/* Safari 4.0 - 8.0 */
@-webkit-keyframes example {
0%{ opacity:.4;}
100%{opacity:1;}
}

/* Standard syntax */
@keyframes example {
0%{ opacity:.4;}
100%{opacity:1;}
}
<div><p>Sample text here.</p></div>

最佳答案

您正在更改的不透明度适用于该 div 内的所有内容,子项也是如此。解决这个问题的方法是不改变不透明度,而只改变背景。您可以使用 rgba() 来做到这一点,它包含一个 opacity 设置,而不是像“红色”这样的纯色背景。

div {
width: 100px;
height: 100px;
background-color: rgba(255, 0, 0, 1);
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
-webkit-animation-duration: 4s; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 4s;
}

div p {
position: absolute;
top: 25px;
}

/* Safari 4.0 - 8.0 */
@-webkit-keyframes example {
0%{background-color: rgba(255, 0, 0, 0.4);}
100%{background-color: rgba(255, 0, 0, 1);}
}

/* Standard syntax */
@keyframes example {
0%{background-color: rgba(255, 0, 0, 0.4);}
100%{background-color: rgba(255, 0, 0, 1);}
}
<div><p>Sample text here.</p></div>

关于html - CSS 动画行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50272446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com