This article introduces the detailed explanation of CSS transparent attributes and the background transparent inheritance solution hack, if you are using the css transparent background and other such articles, this article can help you solve many incompatibility problems. transparency often produces good web visual effects. First, we will provide CSS Transparent Code compatible with mainstream browsers:
The Code is as follows:
. Transparent_class {
Filter: alpha (opacity = 50 );
-Moz-opacity: 0.5;
-Khtml-opacity: 0.5;
Opacity: 0.5;
}
The preceding attributes are as follows:
Opacity: 0.5; this is the most important because it is the CSS standard. This attribute supports Firefox, Safari, and Opera.
Filter: alpha (opacity = 50); this is set for IE6, the value can be 0-100, and the other three 0 to 1.
-Moz-opacity: 0.5; To support earlier Mozilla browsers.
-Khtml-opacity: 0.5; to support some older versions of Safari browsers.
CSS transparency inheritance
However, the transparency attribute of CSS involves an inheritance problem. When transparency is set for the parent element, the child element automatically inherits its transparency, even if you specify transparency as 1 for the child element, it is invalid.
When the sub-element is text, my solution is to check the number of sub-elements, regardless of the number of sub-elements. Another compromise is to specify a relatively deeper color for the text book element. That is to say, when the child element inherits transparency, the text color is exactly what you want. The premise is that the color may be deepened, and the color and transparency values need to be calculated in detail.
There is also a saying "discontinuing transparency", which is not accurate. As far as I know, there is no way to cancel transparency inheritance. It can only be said that some Hack can be used when you want to "overwrite multiple elements and make the specified elements transparent.
After searching, find a good method to achieve this effect-a question about transparency inheritance. If you are interested, you can check it out. The principle is very simple. Adding an empty element as a transparent layer is similar to the element that does not want to be transparent but needs to be overwritten. The parent element uses position: relative to locate, and the two child elements use position: absolute to locate and overwrite.
Html code:
The Code is as follows:
No text image transparency here
Image
CSS code
The Code is as follows:
Body {
Background-image: url (./105247.png );
Background-repeat: repeat;
}
. P2 {width: 100px; height: 100px; background: url (./testbok.png )}
. P3 {width: 200px; height: 200px; position: relative; margin-top: 10px}
. P4 {position: absolute; top: 0; height: 200px; width: 200px; z-index:-1; background: # FFFFFF; filter: alpha (opacity = 70 ); opacity: 0.7 ;}
If the height of the container outside you is unstable, you only need to set the p3 height to a sufficient height.
This method has a bad disadvantage: An empty p