Css 白色透明div
我制作了一个白色透明的div来突出我的内容。我知道正在使用背景色:rgba(255,255,255,0.5)代码>但我也有背景图像。我怎样才能用背景图像也有白色的透明色呢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 {
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;
}