在 <div>
中时,有什么方法可以使内容/图像不透明吗?有透明度吗?
这是 HTML:
<div id="main-button-wrapper" class="left">
<div id="button-bg-layer" class="box-bg-layer corners"></div>
<div class="buttons-bg-overlay box-bg-overlay corners">
<img alt="Test" src="http://www.schroff.co.uk/railway/src/symbol_test.gif" />
</div>
</div>
CSS:
#main-button-wrapper {
height: 319px;
margin-left: 22px;
position: relative;
width: 321px;
}
#button-bg-layer {
position: absolute;
right: 0;
height: 319px;
width: 321px;
}
.buttons-bg-overlay {
position: relative;
right: 0;
margin: 11px;
height: 66px;
width: 299px;
text-align: center;
padding-top: 26px;
}
#buttons-wrapper {
position: relative;
width: 299px;
height: 297px;
z-index: 3;
margin: 22px;
}
/* Background Layers */
.box-bg-layer {
background-color: #010101;
z-index: 1;
zoom: 1;
filter: alpha(opacity=40);
opacity: 0.4;
}
.box-bg-overlay {
background-color: #010101;
z-index: 2;
zoom: 1;
filter: alpha(opacity=40);
opacity: 0.4;
}
我试过放一个 z-index: 4;
在图像上。我能想到的唯一其他方法是将 div 背景设置为绝对定位,然后将内容定位在 div 之外,但必须有更简单的方法吗?
如有任何帮助,我们将不胜感激!
参见 JSFiddle:
最佳答案
不要使用opacity
,而是使用rgba
其中 a
代表 alpha
。这将使子元素不透明...
background-color: rgba(0,0,0,.5); /* RGBA for #010101 will be rgba(1,1,1,.4) */
.4
对于 a
相当于 opacity: 0.4
关于html - CSS - 将 <divs> 置于透明的 <div> 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806146/