Remove inheritance of opacity from parent?

淺唱寂寞╮ 提交于 2019-12-13 04:35:03

问题


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

Here is my code:

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

And this my css code.

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

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

How can I do this?


回答1:


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

Instead, use rgba values:

#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
}

See this SO question for more info



来源:https://stackoverflow.com/questions/21080235/remove-inheritance-of-opacity-from-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!