问题
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