To set the background for an element to be transparent, in Chrome, Firefox, and Opera:
Background-color:rgba (0, 0, 0, 0.4);
The last parameter in RGBA 0.4 is the desired transparency, which ranges between 0~1.
This is usually the case in IE:
Background-color:rgb (0, 0, 0); Filter:alpha (opacity=40);
Opacity represents transparency, and its value range is between 0~100
So how is it compatible with each browser? Just write them together.
Because IE does not support RGBA, it is ignored. Other browsers are generally ignored for what they don't support.
Here's an example:
HTML Code:
<body><p class= "non-transparent" >aaaaa</p></body><p class= "Transparent" ><p class = "box" >box</p></p>
CSS Code:
. non-transparent:hover {background-color:yellow;}. Transparent {position:absolute;top:0;left:0;text-align:center;width:100%;height:100%;filter:alpha (opacity=40); Background-color:rgb (0, 0, 0); Background-color:rgba (0, 0, 0, 0.4);}. box {background-color:yellow;width:50%;height:50%;p osition:relative;left:5%;top:10%;}
Display effect:
Chrome:
Firefox
Opera
IE8:
In addition, you can do this in Chrome, Firefox, and Opera:
opacity:0.4;
However, the transparency of all child elements is also set to the same value, such as: