使文本背景透明,但文本本身不透明

问题描述 投票:84回答:5

所以我有问题。我环顾四周,环顾四周,但没有运气。我想使我的身体背景透明,但使文本不透明。现在,我保持相同的不透明度。这是我的代码:

@charset "utf-8";
body {
    font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
    background-color: #42413C;
    margin: 0;
    padding: 0;
    color: #000;
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { 
    padding: 0;
    margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
    margin-top: 0;
    padding-right: 15px;
    padding-left: 15px;
    opacity:1;
}
a img { 
    border: none;
}
a:link {
    color: #42413C;
    text-decoration: underline;
}
a:visited {
    color: #6E6C64;
    text-decoration: underline;
}
a:hover, a:active, a:focus {
    text-decoration: none;
}
.container {
    width: 750px;
    margin: 0 auto;
}
.content {
    padding:20px;
    width:710px;
    position:relative;
    background:#CCC;
    opacity: 0.5;
}
.fltrt {
    float: right;
    margin-left: 8px;
}
.fltlft { 
    float: left;
    margin-right: 8px;
}
.clearfloat { 
    clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}
.header {
    top:0%;
    width: 750px;
    height: 200px;
    background-image: url(images/header.png);
    background-repeat:no-repeat;
    background-position:center;
}
.navbar {
    height: 50px;
    width: 750px;
    position: relative;
    z-index: 2;
}
#bg {
    position: fixed;
    top: 25%;
    left: 15%;
    z-index: -1;
}
div {
display: block;
}

这是我的网站(单击链接不要在您的URL中输入“ tccraft.net”,它会带您到Facebook页面):http://tccraft.net/index.php谢谢!

html css text opacity
5个回答
167
投票

不要为此使用opacity,而是将背景设置为RGBA值,以仅使背景为半透明。您的情况就是这样。

.content {
    padding:20px;
    width:710px;
    position:relative;
    background: rgb(204, 204, 204); /* Fallback for older browsers without RGBA-support */
    background: rgba(204, 204, 204, 0.5);
}

有关更多信息和css中的rgba值示例,请参见http://css-tricks.com/rgba-browser-support/。>


16
投票

对于完全透明的背景使用:


2
投票

opacity将同时使文本和背景透明。而是使用半透明的背景色,例如,使用rgba()值。在IE8 +上运行]


0
投票

如果您将RGBA用于现代浏览器,则不需要让旧版IE仅使用给定颜色的非透明版本和RGB。


-2
投票
box-shadow: inset 1px 2000px rgba(208, 208, 208, 0.54);
© www.soinside.com 2019 - 2024. All rights reserved.