I want the image inside the div to be opaque and the div to be transparent. I tried setting the opacity for image and div, but it is not working.
jsFiddle Link: http://jsfiddle.net/2BNEF/10/
I want the image to be opaque and text to be visible in transparent.
<div id="targetframe">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
<div id="target">
out. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their defaul
<img class="myimage" src="http://www4.picturepush.com/photo/a/1365552/480/trucks-photgraphy/asdf-%2858%29.jpg?v0"/>
</div>
</div>
#targetframe {
background: none repeat scroll 0 0 black;
border: 2px inset grey;
font-family: Verdana,sans-serif;
left: 0;
margin: 0;
overflow: hidden;
padding: 0;
position: absolute;
top: 0;
opacity: 0.5;
}
#target {
background: none repeat scroll 0 0 transparent;
height: 100%;
left: 0;
position: relative;
top: 0;
width: 100%;
z-index: 0;
}
.myimage {
opacity: 1;
}
If you set opacity
on an element, then it is inherited by all the descendants (children, all the children's children...) of that element and there is nothing you can do to prevent that.
In this case, you could just use an RGBa background (rgba(0,0,0,.5)
instead of black - DEMO) for the div. RGBa has excellent support - the only browsers that don't support it are IE8 and older and for those you can use a filter
gradient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With