简体   繁体   English

CSS背景图片透明

[英]css background image transparent

Original my CSS was, 原来我的CSS是

  .featured .content-wrapper
  {
   background-color: #7ac0da;
    background-image: -ms-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
    background-image: -o-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
    background-image: -webkit-gradient(linear, left top, right top, color-stop(0, #7ac0da), color-stop(1, #a4d4e6));
    background-image: -webkit-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);

    color: #3e5667;
    padding: 20px 40px 30px 40px;
   }

The displaying likes: 显示喜欢: 旧形象

Then I wanted to add an image, the CSS became: 然后我想添加一个图像,CSS变为:

   .featured .content-wrapper
   {
     background-color: #7ac0da;
     background-image: -ms-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
     background-image: -o-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
     background-image: -webkit-gradient(linear, left top, right top, color-stop(0, #7ac0da), color-stop(1, #a4d4e6));
     background-image: -webkit-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
     background-image: url('../Images/love.png');
     color: #3e5667;
     padding: 20px 40px 30px 40px;
   }

I only added one image 我只添加了一张图片

background-image: url('../Images/love.png'); 背景图片:url('../ Images / love.png');

Now it shows: 现在显示: 新图片

What I want is to make the background color #3e5667 is still visible. 我要使背景颜色#3e5667仍然可见。

How to modify the CSS? 如何修改CSS?

You can define a background image and a gradient simultaneously in CSS3 like this: 您可以在CSS3中同时定义背景图片和渐变,如下所示:

background: #7ac0da;
background-image: url('../Images/love.png'); /* fallback */
background-image: url('../Images/love.png'), -webkit-gradient(linear, left top, left bottom, from(#7ac0da), to(#999999)); /* Saf4+, Chrome */
background-image: url('../Images/love.png'), -webkit-linear-gradient(top, #7ac0da , #a4d4e6 ); /* Chrome 10+, Saf5.1+ */
background-image: url('../Images/love.png'), -moz-linear-gradient(top, #7ac0da , #a4d4e6 ); /* FF3.6+ */
background-image: url('../Images/love.png'), -ms-linear-gradient(top, #7ac0da , #a4d4e6 ); /* IE10 */
background-image: url('../Images/love.png'), -o-linear-gradient(top, #7ac0da , #a4d4e6 ); /* Opera 11.10+ */
background-image: url('../Images/love.png'), linear-gradient(top, #7ac0da , #a4d4e6 ); /* W3C */ 

You need to make sure your image (love.png) has a transparent background. 您需要确保图像(love.png)具有透明背景。 At the moment it has a dark grey background and that's being shown over the top of the blue one you've added in CSS. 目前,它具有深灰色背景,并显示在您在CSS中添加的蓝色背景的上方。

You could try 你可以试试

background-repeat:no-repeat;
background-position:center center;

Is that what you mean? 你是这个意思吗?

It's just because you are overriding the bg with the image. 只是因为您要用图像覆盖bg。 I suggest either creating a wrapper in your HTML or using a CSS psudo-element to compensate. 我建议要么在HTML中创建包装器,要么使用CSS伪元素进行补偿。

.featured .content-wrapper
{
   background-color: #7ac0da;
   background-image: -ms-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
   background-image: -o-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
   background-image: -webkit-gradient(linear, left top, right top, color-stop(0, #7ac0da), color-stop(1, #a4d4e6));
   background-image: -webkit-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
   color: #3e5667;
   padding: 20px 40px 30px 40px;

   position:relative;
}

.featured .content-wrapper:after
{
   content: '';
   position:absolute;
   background-image: url('../Images/love.png');
   width:100%;
   height:100%;
   left:0%;
   top:0%;
}

or something like that. 或类似的东西。 Note that this doesn't work on all versions of IE and of course ensure your background on your image is fully transparent. 请注意,这不适用于所有版本的IE,当然要确保图像的背景是完全透明的。

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

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