繁体   English   中英

图像上的透明彩色背景在悬停时删除

[英]Transparent color background on image remove on hover

我遇到了一个问题,我在图像上放置了透明的彩色背景,并且部分显示了图像,并且当用户将鼠标悬停在该颜色上以显示图像时,我希望该颜色的不透明度为0.0(消失)。

这是我的代码:

#music{
    /*background-color: #13505B;*/
    background: url('../images/music.jpg'); 
}


#music::before{
    position:absolute;
    content: ""; 

    top: 0;
    bottom: 0;
    right: 0;
    left: 0;

    transition: background 0.5s ease; 
    z-index: 1;
    background-color: rgba(19, 80, 91, 0.7) !important;
}

#music:hover::before{
    background-color: rgba(19, 80, 91, 0.0) !important;
}

我还无法获得这种效果。 任何帮助表示赞赏。

您需要添加position: relative; #music 我想就是这样。 我只是为缺少图像添加了background-color

 #music{ background-color: deeppink; height: 300px; width: 300px; position: relative; } #music::before{ position:absolute; content: ""; top: 0; bottom: 0; right: 0; left: 0; transition: background 0.5s ease; z-index: 1; background-color: rgba(19, 80, 91, 0.7); } #music:hover::before{ background-color: rgba(19, 80, 91, 0.0); } 
 <div id="music"></div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM