Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 白色透明div_Css_Background - Fatal编程技术网

Css 白色透明div

Css 白色透明div,css,background,Css,Background,我制作了一个白色透明的div来突出我的内容。我知道正在使用背景色:rgba(255,255,255,0.5)但我也有背景图像。我怎样才能用背景图像也有白色的透明色呢 .div { width: auto; padding: 20px; height: 80px; background: url('../img/dark_embroidery.png'); background-repeat: repeat; background-color:

我制作了一个白色透明的div来突出我的内容。我知道正在使用背景色:rgba(255,255,255,0.5)但我也有背景图像。我怎样才能用背景图像也有白色的透明色呢

.div {
    width: auto;
    padding: 20px;
    height: 80px;
    background: url('../img/dark_embroidery.png');
    background-repeat: repeat;  
    background-color: rgba(255, 255, 255, 0.5);
}

背景图像下的背景色。如果图像不是透明的,并且具有完整的div大小,则隐藏白色背景

可以使用第二个元素设置白色覆盖

<style>
    .div {/* your styles */}
    .div > div {background: rgba(255, 255, 255, .5)}
</style>    

<div class=div>
    <div>
        CONTENT
    </div>
</div>

.div{/*您的样式*/}
.div>div{背景:rgba(255,255,255,5)}
内容


或者,第二种方法,使png图像透明(或者更好地说,为png图像添加不透明度)。

背景图像下的背景色。如果图像不是透明的,并且具有完整的div大小,则隐藏白色背景

可以使用第二个元素设置白色覆盖

<style>
    .div {/* your styles */}
    .div > div {background: rgba(255, 255, 255, .5)}
</style>    

<div class=div>
    <div>
        CONTENT
    </div>
</div>

.div{/*您的样式*/}
.div>div{背景:rgba(255,255,255,5)}
内容


或者,第二种方法,使png图像透明(或者更好地说,为png图像添加不透明度)。

无需编辑图像或使用其他标记,您可以使用绝对定位的伪元素来实现这一点

为您的
div
提供以下样式:

.div{
    background:url(../img/dark_embroidery.png) no-repeat;
    height:80px;
    padding:20px;
    position:relative;
    width:auto;
}
.div:before{
    background:rgba(255,255,255,.5);
    bottom:0;
    content:"";
    display:block;
    left:0;
    position:absolute;
    right:0;
    top:0;
}
另一种选择是使用多个背景。您可以通过提供一个逗号分隔的背景列表来实现,该列表将按照提供的顺序从上到下分层。但是请注意,这里只能使用图像,因此您需要为白色使用渐变

.div{
    background:linear-gradient(0deg,rgba(255,255,255,.5),rgba(255,255,255,.5)),url(../img/dark_embroidery.png) no-repeat;
    height:80px;
    padding:20px;
    position:relative;
    width:auto;
}

    • 无需编辑图像或使用其他标记,您可以使用绝对定位的伪元素来实现这一点

      为您的
      div
      提供以下样式:

      .div{
          background:url(../img/dark_embroidery.png) no-repeat;
          height:80px;
          padding:20px;
          position:relative;
          width:auto;
      }
      .div:before{
          background:rgba(255,255,255,.5);
          bottom:0;
          content:"";
          display:block;
          left:0;
          position:absolute;
          right:0;
          top:0;
      }
      
      另一种选择是使用多个背景。您可以通过提供一个逗号分隔的背景列表来实现,该列表将按照提供的顺序从上到下分层。但是请注意,这里只能使用图像,因此您需要为白色使用渐变

      .div{
          background:linear-gradient(0deg,rgba(255,255,255,.5),rgba(255,255,255,.5)),url(../img/dark_embroidery.png) no-repeat;
          height:80px;
          padding:20px;
          position:relative;
          width:auto;
      }
      

      您必须使图像透明。您也可以使用“不透明度”属性:您想要这样的效果。你必须使图像透明。你也可以使用不透明属性:你想要这样的效果。