【发布时间】:2013-06-12 17:12:21
【问题描述】:
今天早些时候我问过Overlay a background-image with an rgba background-color。我的目标是拥有一个带有背景图像的 div,当有人悬停 div 时,背景图像会被 rgba 颜色覆盖。在the answer,给出了:after的解决方案:
#the-div {
background-image: url('some-url');
}
#the-div:hover:after {
content: ' ';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0,0,0,.5);
}
我现在想拥有相同的效果,但使用 CSS 过渡:我希望背景颜色淡入。我尝试将 transition: all 1s; 添加到 #the-div CSS,但没有奏效。我也尝试将它添加到#the-div:hover 和#the-div:after,但这也没有用。
是否有一种纯 CSS 方法可以将淡入淡出的叠加层添加到带有背景图像的 div 中?
【问题讨论】:
标签: css overlay background-image css-transitions