html - CSS - 将 <divs> 置于透明的 <div> 之上

标签 html css

<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:

http://jsfiddle.net/Sa8jw/

最佳答案

不要使用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

Demo

关于html - CSS - 将 <divs> 置于透明的 <div> 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806146/

相关文章:

javascript - jQuery - 结合 slideToggle 和动画时闪烁

javascript - 页面滚动,保持页面垂直,部分页面水平

javascript - Javascript 中的 CSS

php - 使用 css/php stylesswitcher 在移动和标准 View 之间来回切换

html - 为什么 &lt;textarea&gt; 和 &lt;input&gt; 元素不遵守最大宽度?

html - 电子邮件通讯无法正确呈现

javascript - 如何使用 Javascript 作为 accesskey 覆盖/禁用 Firefox 菜单快捷键

html - 火狐渲染背景图

css - css中的孤儿寡母是什么?

css - 使 div 稍微偏离中心