CSS transparency settings in the design of the Web page is often needed, and sometimes in order to design the page more beautiful, will be transparent to the image processing, so that the content on the page will not be invisible, and some Web pages because the picture as the background, will be more beautiful, then,
How does the transparency in CSS be set? This article is to share with you today.
How to set the transparency of images in CSS。
There are two properties associated with setting the transparency effect in CSS: Opacity and RGBA. (Recommended video lesson: CSS Tutorial)
Let's use these two properties to set the effect of the transparency of the picture separately.
First, let's look at the example of opacity property setting image transparency in CSS
Css:
. Opacity1,. Opacity2,. opacity_img {display:inline-block;}. opacity1 {filter:alpha (opacity=0);}. Opacity2 {filter:alpha (opacity=50);}. opacity_img {filter:alpha (opacity=100);}:root. opacity1 {opacity:0; filter:none;}:root. opacity2 {opacity:. 5; fil Ter:none; }:root. opacity_img {opacity:1; filter:none;}
Html:
<p> <a href= "#" class= "Opacity2" > </a> </p><p> <a href= "#" class= "Opacity2" > </a></p>
The effect is as follows:
Note: The current mainstream browser supports Opacity:value notation, value is 0-1,0 to full transparency, and 1 is completely opaque. However, this notation is not supported in IE8 and previous versions, so we can resolve Filter:alpha (opacity=value) with a filter, value is 0-100,0 to be fully transparent, and 100 is completely opaque. Just like the example above.
Let's look at the example of the transparency of RGBA settings in CSS:
Html:
<div class= "DEMO2-BG" > <div class= "Demo2" > Background translucent, text opaque <br/> Method: Positioning + Background:rgba ( 255,255,255,0.3) </div></div>
Css:
. demo2-bg{ Background:url (//image.zhangxinxu.com/image/study/s/s256/mm1.jpg) no-repeat; Background-size:cover; width:500px; height:300px; Position:relative;}. demo2{ Position:absolute; left:0; right:0; top:0; bottom:0; width:500px; height:300px; line-height:50px; Text-align:center; Background:rgba (255,255,255,0.3);
The effect is as follows:
Description: This method browser compatibility is good, the picture and content can be separated to achieve the background image translucent effect, and text, borders and other styles and content is not affected. Just a layer of div, using an absolute positioning style to achieve overlapping stacking.
Sets the background color value and transparency. The first 3 255 represents RGB black, and 0.3 for transparency is 30%.
Finally, let's look at a picture of how the frosted glass effect is set up:
<div class= "Demo1" > Background map Translucent, text opaque <br/> Method: Background map + filter:blur</div>
. demo1{ width:500px; height:300px; line-height:50px; Text-align:center;}. demo1:before{ Background:url (//image.zhangxinxu.com/image/study/s/s256/mm1.jpg) no-repeat; Background-size:cover; width:500px; height:300px; Content: ""; Position:absolute; top:0; left:0; Z-index: -1;/*-1 can be background * /-webkit-filter:blur (3px); Filter:blur (3px);}
The effect is as follows:
This article ends here, more about the CSS image processing methods can refer to the CSS manual.