从父级删除不透明度的继承? [英] Remove inheritance of opacity from parent?

查看:162
本文介绍了从父级删除不透明度的继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 div 标签。我想删除 #overlay 的不透明度

I have a div tag. I want to remove the children's inheritance of #overlay's opacity

这里是我的代码:

<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/

I want to have like this site background: http://www.ehsanakbari.ir/

我该如何做?

推荐答案

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

You cannot stop children elements from inheriting their parent's opacity because that is done post-rendering

而是使用 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
}

href =http://stackoverflow.com/questions/5770341/i-do-not-want-to-in-the-parent-in-css>此SO问题更多信息

See this SO question for more info

这篇关于从父级删除不透明度的继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆