Home >Web Front-end >CSS Tutorial >How to Maintain Opacity in Div Backgrounds in IE8?
In Internet Explorer 8, adjusting the opacity of a div's background can affect the elements it contains.
To address this issue, set the background color using the rgba() function:
.myelement { background: rgba(200, 54, 54, 0.5); }
The fourth value in rgba() represents the alpha channel, controlling opacity.
Unfortunately, rgba() is not supported in IE8. To enable it, utilize CSS3Pie:
.myelement { background: rgba(200, 54, 54, 0.5); -pie-background: rgba(200, 54, 54, 0.5); behavior: url(PIE.htc); }
Alternatively, IE's filter property with the gradient keyword can achieve a similar effect:
.myelement { filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#33c8348a, endColorstr=#33c8348a); }
While rgba() with CSS3Pie is recommended for cleaner stylesheets, the filter approach remains viable.
The above is the detailed content of How to Maintain Opacity in Div Backgrounds in IE8?. For more information, please follow other related articles on the PHP Chinese website!