html - 透明框上的不透明文本

标签 html css text transparency

我想在我的透明框中使用不透明文本。这是一个代码示例:

HTML:

<div id="Transparent_Box">                                          
    <div class="text">                                          
    <h1>Some opaque text</h1>
    </div>  
</div>

CSS:

#Transparent_box {      
    url(../images/header-bg.png);
    background:url(../images/header-bg.png) repeat-x\0/; 
    background-position:center bottom, left top;
    background-repeat:repeat-x;
    overflow:hidden;
    background-color:#FFF;
    opacity: 0.6;
    filter: alpha(opacity=60);  

}

.text {
float:left;
margin-top:30px;
width:490px;
margin-left:20px;
opacity: 1;
filter: alpha(opacity=100);
}

.text h1 {
    font-weight:900;
    color:#FFF;
    line-height:34px;
    margin-top:8px;
    opacity: 1;
    filter: alpha(opacity=100);
}

由于继承,文本始终显示为半透明。有没有办法在我的透明框上获得漂亮的不透明文本?


谢谢,就是这样...我现在还添加了一个透明的 .png 背景 它看起来像这样:

background-image:url(../images/header-shadow.png), url(../images/header-bg.png);
background:url(../images/header-bg.png) repeat-x\0/; 
background-position:center bottom, left top;
background-repeat:repeat-x;
background-color: rgba(0,0,0,0)

这应该在 IE8 及以下版本下工作。

最佳答案

使用透明背景色代替不透明度。无需额外标记。

div {
  background: rgba(0,0,0,.5)
}

Demo

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

相关文章:

sql-server - SQL Server 数据库中所有依赖项的树

python - 在大空白处分割 Pandas

css - HTML 5 浏览器和分辨率与 XHTML 的兼容性

php - 网络机器人可以增加下载量吗?

html - 不使用 <fieldset> 标签是否可以实现类似 <fieldset> 的效果?

html - 如何通过css给图片添加url?

jQuery 添加和删除文本框

html - 为什么 CSS 不透明度会影响上面的 div?

html - 将可点击的帮助图标添加到 Bootstrap 导航栏中的导航栏菜单项

html - 如何确定 CSS 切换输入的 'toggle' 状态?