Setting Opacity of div's Background Without Affecting Contained Elements in IE 8
The opacity style affects both the parent element and its child elements, which can be undesirable in certain scenarios. To set the opacity of a div's background without impacting the contained elements, consider using a different approach:
Using rgba() Background Color
The rgba() function allows you to specify the red, green, blue (RGB) values, as well as an alpha channel value. The alpha channel value determines the opacity. For example:
.myelement { background: rgba(200, 54, 54, 0.5); }
Here, the first three numbers represent the RGB color values, while 0.5 represents the alpha channel opacity (50%).
IE-Specific Solution: CSS3Pie
However, this method does not support IE 8 and below. To address this, you can use the CSS3Pie polyfill. CSS3Pie provides support for various modern CSS3 features, including rgba background colors. To use it:
.myelement { background: rgba(200, 54, 54, 0.5); -pie-background: rgba(200, 54, 54, 0.5); behavior: url(PIE.htc); }
Alternative: IE's Filter Style with Gradient
Another alternative that works in IE is using the filter style with the gradient keyword. However, this approach is less intuitive and requires direct interaction with IE's filters.
Additional Notes
The above is the detailed content of How to Set Opacity of a Div's Background Without Affecting Contained Elements in IE 8?. For more information, please follow other related articles on the PHP Chinese website!