简体   繁体   English

在HTML或CSS中更改图像的背景颜色

[英]Change Image's Background Color in HTML or CSS

I just downloaded an html template, in that I can see the images having white background, but when those are used in site, they have background color changed. 我刚刚下载了一个html模板,可以看到具有白色背景的图像,但是当在站点中使用这些图像时,它们的背景颜色也发生了变化。

原始图片

And this is what I see in the site: 这就是我在网站上看到的:

网站中的图片

So How to achieve this effect, I spent whole night changing background color of an image in photoshop, that does not look as good as it is in this image, 因此,如何实现这种效果,我整夜都在photoshop中更改了图像的背景颜色,但看起来并不像这张图像那样好,

So there must be some method in CSS to do this..? 因此,在CSS中必须有某种方法可以做到这一点。

This is done by image type. 这是通过图像类型完成的。 You likely need a PNG with transparency. 您可能需要具有透明性的PNG。 If you are familiar with photoshop, you just erase the background (so the alpha-layer can show through there) and then save an a png. 如果您熟悉Photoshop,则只需擦除背景(以便Alpha层可以在其中显示),然后保存png。 This will let the background color "show through" the image. 这将使背景色“显示”图像。

Try this 尝试这个

img {
    background-color : blue;
}

This will appear on when you use a png transparent image. 当您使用png透明图像时,它将显示在屏幕上。

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

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