【问题标题】:Remove inheritance of opacity from parent?从父级删除不透明度的继承?
【发布时间】:2014-01-31 13:06:46
【问题描述】:

我有一个div 标签。我想去掉#overlay的不透明度的子孙继承

这是我的代码:

<body id="bg">
    <div id="overlay">
        <header id="colortext">dgjdhgjdhd</header>
    </div>
</body>

这是我的 CSS 代码。

#bg{
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    background-image: url(../Images/bg.jpg);
}
#overlay{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background-color: #000;
    -moz-opacity:0.5;
    -khtml-opacity: 0.5;
    opacity: 0.5;
}
#colortext{
    background-image:none;
    margin-top: 7px;
    margin-left: 16px;
    top: 2%;
    left: 2%;
    color: #FFFFFF;
    text-align: left;
    font-size: xx-large;
    opacity:1 !important;
}

我想拥有这样的网站背景:http://www.ehsanakbari.ir/

我该怎么做?

【问题讨论】:

  • “移除继承”是什么意思?
  • 我想禁用从 div 中的所有使用标签继承
  • 我想我明白你的意思了。您想使用子选择器; div#overlay&gt;* 这将仅匹配您 div 的所有直系子级。然后应用从 div 中重置规则的规则。
  • 对不起。我的英语很糟糕。但我希望我能明白我的意思
  • 啊……不幸的是,这并不容易,恐怕。不过,这本身不是继承问题。

标签: css html inheritance overlay opacity


【解决方案1】:

您不能阻止子元素继承其父元素的不透明度,因为这是在渲染后完成的

改为使用rgba 值:

#overlay{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background-color: rgba(0,0,0,0.5);
           // red, green, blue, opacity
}

更多信息请见this SO question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多