opacity
on parent element sets it for the whole sub DOM treeYou can't really set opacity for certain element that wouldn't cascade to descendants as well. That's not how CSS opacity
works I'm afraid.
What you can do is to have two sibling elements in one container and set transparent one's positioning:
<div id="container">
<div id="transparent"></div>
<div id="content"></div>
</div>
then you have to set transparent position: absolute/relative
so its content sibling will be rendered over it.
rgba
can do background transparency of coloured backgroundsrgba
colour setting on element's background-color
will of course work, but it will limit you to only use colour as background. No images I'm afraid. You can of course use CSS3 gradients though if you provide gradient stop colours in rgba
. That works as well.
But be advised that rgba
may not be supported by your required browsers.
But if you're after some kind of masking the whole page, this is usually done by adding a separate div
with this set of styles:
position: fixed;
width: 100%;
height: 100%;
z-index: 1000; /* some high enough value so it will render on top */
opacity: .5;
filter: alpha(opacity=50);
Then when you display the content it should have a higher z-index
. But these two elements are not related in terms of siblings or anything. They're just displayed as they should be. One over the other.