使文本背景透明而不是文本本身

新手上路,请多包涵

所以我遇到了问题。我环顾四周,环顾四周,但没有运气。我想让我的身体背景透明,但让文字不透明。就像现在一样,我一直在制作相同的不透明度。这是我的代码:

 @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;
}

这是我的网站(点击链接,不要在您的网址中输入“tccraft.net”,它将带您进入 facebook 页面): http ://tccraft.net/index.php 谢谢!

原文由 tec4 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 364
2 个回答

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

原文由 Karl-Johan Sjögren 发布,翻译遵循 CC BY-SA 3.0 许可协议

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

 background: transparent;

否则对于半透明颜色填充使用:

 background: rgba(255,255,255,0.5); // or hsla(0, 0%, 100%, 0.5)

其中的值是:

 background: rgba(red,green,blue,opacity); // or hsla(hue, saturation, lightness, opacity)

您还可以将 rgba 值用于渐变背景。

要在图像背景上获得透明度,只需预先在您选择的图像编辑器中降低图像的不透明度即可。

原文由 James Coyle 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题