2

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?

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
user3188238
  • 35
  • 1
  • 6

1 Answers1

3

You cannot stop children elements from inheriting their parent's opacity.

Instead, you could use an rgba value for the parent's background color instead of opacity:

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

See this SO question for more info.

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147