我如何淡入/淡出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;
}
答案 0 :(得分:3)
通过淡化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>