gpt4 book ai didi

html - 如何只淡化 div,而不淡化文本?

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:07 24 4
gpt4 key购买 nike

如何只淡入/淡出 div,而不淡入/淡出 div 中的文本?

这是我的代码:https://jsfiddle.net/tc6fq235/3/

<div class="fade">Hover over me.</div>

.fade {
background-color: antiquewhite;
width: 300px;
height: 200px;
text-align: center;

opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}

.fade:hover {
opacity: 0.5;
}

最佳答案

通过淡化 div,您将淡化其中的文本,因为文本是 div 的一部分。如果您只想淡化背景颜色(div 的唯一其他可见部分,而不是文本),您可以使用 alpha 透明度。

.fade {
background-color: antiquewhite;
width: 300px;
height: 200px;
text-align: center;
transition: background-color .25s ease-in-out;
}

.fade:hover {
background-color: rgba(250,235,215,0.5);
}
<div class="fade">Hover over me.</div>

关于html - 如何只淡化 div,而不淡化文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41905754/

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