简体   繁体   English

对具有背景颜色的父 div 中的 PNG 图像(透明)进行叠加 hover 效果的问题

[英]Issue with making an overlay hover effect to a PNG image (transparent) in a parent div with a background color

I believe this is simple but I cannot seem to figure it out.我相信这很简单,但我似乎无法弄清楚。 I want to create an overlay hover effect on an image, but I'm having trouble with a PNG image that has the transparency in it.我想在图像上创建叠加 hover 效果,但是我在使用具有透明度的 PNG 图像时遇到了问题。 The black background from the parent div element is filling the transparent parts of the PNG image as if the parts of the image are set in opacity: 0 by default.父 div 元素的黑色背景填充 PNG 图像的透明部分,就好像图像的部分设置为 opacity: 0 默认情况下。

Here's my html这是我的 html

<div class="parent">
<img src="transparent.png"/>
</div>

Here's my css这是我的 css

.parent {
background-color: #000000;
}
.parent img:hover {
opacity: .7;
}

在此处输入图像描述

Here is the solution, not much to say, but the values needs to be changed accordingly, i have just used values to display the function.这里是解决方案,不多说,但是数值需要相应地改变,我刚刚用数值来显示function。 Read the comments of the codes阅读代码的注释

 .parent { background-color: #000000; }.parent img:hover { opacity: .1; /*change this accordingly*/ background: rgba(255,255,255,0.5); /*Last value of rgba is opacity, 0.0 -> 1.0*/ }.parent img { background: rgba(255,255,255,1);; }
 <div class="parent"> <img src="https://www.lunapic.com/editor/premade/transparent.gif"/> </div>

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

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