To create a cross-browser solution, you can use the opacity property on an additional child element that is "absolutely positioned" within a relatively or absolutely positioned parent. This child element is simply there to contain the colored transparent background.
By utilizing the opacity
property, you can make this element transparent without affecting any other elements since it has no children.
Opacity is supported in IE5 and above, and you can implement it using the following methods (refer to http://css-tricks.com/snippets/css/cross-browser-opacity/):
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 8 */
filter: alpha(opacity=50); /* IE 5-7 */
-moz-opacity: 0.5; /* Netscape */
-khtml-opacity: 0.5; /* Safari 1.x */
opacity: 0.5; /* Good browsers */
For a demonstration, refer to the jsFiddle example at http://jsfiddle.net/DUjzX/1/.
The complete code looks like:
HTML structure:
<div class="my-cool-wrapper">
<div class="text-and-images-on-top">
<p>Here's some content (text and images) displayed on top of the transparent background.</p>
<img src="http://i.imgur.com/LnnghmF.gif">
</div>
<div class="transparent-background">
</div>
</div>
CSS styles:
.my-cool-wrapper {
position: relative;
}
.my-cool-wrapper .text-and-images-on-top {
padding: 10px 15px 19px 15px;
z-index: 1;
position: relative; /* needed for z-index */
}
.my-cool-wrapper .transparent-background {
position: absolute;
top: 0;
width: 100%;
height: 100%;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=10)"; /* IE 8 */
filter: alpha(opacity=10); /* IE 5-7 */
-moz-opacity: 0.1; /* Netscape */
-khtml-opacity: 0.1; /* Safari 1.x */
opacity: 0.1; /* Good browsers */
background-color: blue;
}
For more information, visit:
Set opacity of background image without affecting child elements
Proofs through screenshots
PS: Screenshots for Chrome, Firefox, and Safari are omitted as they are considered "better" browsers—rest assured, the solution works for them as well.