This question already has an answer here:
Hey i am searching in google but i can't fine any perfect answer
I want to Opacity in parent DIV but not Child DIV
Example
HTML
<div class="parent">
<div class="child">
Hello I am child
</div>
</div>
Css
.parent{
background:url('../images/madu.jpg') no-repeat 0 0;
}
.child{
Color:black;
}
Note: -- I want to background-image in Parent Div
not Color
May be it's good if you define your background-image in the
:after
pseudo class. Write like this:Check this fiddle
I had the same problem and I fixed by setting transparent png image as background for the parent tag.
This is the 1px x 1px PNG Image that I have created with 60% Opacity of black background !
You can do it with pseudo-elements: (demo on dabblet.com)
your markup:
css:
You can't do that, unless you take the child out of the parent and place it via positioning.
The only way I know and it actually works, is to use a translucid image (.png with transparency) for the parent's background. The only disavantage is that you can't control the opacity via CSS, other than that it works!
I know this is old, but just in case it will help someone else.
Where
rgba
is: red, green, blue, anda
is for transparency.As mentioned by Tom,
background-color: rgba(229,229,229, 0.85)
can do the trick. Place that on the style of the parent element and child wont be affected.