html - 图像上的透明 div 但文本不透明

标签 html css

我有以下 HTML 代码,它只显示一个带有包含文本的透明黑色覆盖层的图像。

我不希望我的文字是透明的。我尝试使用 z-index,但我的文本仍然是透明的:

Demo

我的代码有什么问题?

这是我的 HTML:

<div class="leftContainer">
    <div class = "promo">
         <img src="images/soon.png" width="415" height="200" alt="soon event" />

         <div class="hilight">
             <h2>Hockey</h2>
             <p>Sample text</p>
         </div>

     </div>

     ...

</div>

这是我的CSS:

.hilight h2{
    font-family: Helvetica, Verdana;
    color: #FFF;
    z-index: 200;
}

.promo {
    position: relative;
}
.promo img {
    z-index: 1;
}

.hilight {
    background-color: #000;
    position: absolute;
    height: 85px;
    width: 415px;
    opacity: 0.65;
    font-family: Verdana, Geneva, sans-serif;
    color: #FFF;
    bottom: 0px;
    z-index: 1;
}

最佳答案

将 .hilight 的背景更改为 rgba(0,0,0,0.65) 并移除不透明度。

.hilight {
 background-color: rgba(0,0,0,0.65);
 position: absolute;
 height: 85px;
 width: 415px;
 font-family: Verdana, Geneva, sans-serif;
 color: #FFF;
 bottom: 0px;
 z-index: 1;
}

关于html - 图像上的透明 div 但文本不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16679093/

相关文章:

javascript - 重定向到 cordova 应用程序中的另一个页面后无法运行 javascript

html - 使用过渡文档类型有哪些缺点?

html - Jade If 语句不适用于变量

javascript - 元素像亚马逊帮助页面一样悬停

asp.net - CSS 与 IE6 下拉问题

html - CSS - 防止弹出窗口隐藏在页面上的其他元素后面

jquery - 使用 Google Gauge 的 jQuery 或 CSS 文本 SVG 移动底部

iphone - Safari Mobile 在纵向模式下旋转用手机相机拍摄的照片

javascript - 如何禁用按钮组(Bootstrap)中的按钮?

html - Opera 在选择元素上设置背景颜色时隐藏下拉列表中的文本