Day 161th: CSS3 gradient background (gradient) effect for compatibility

Source: Internet
Author: User

CSS for compatibility gradient background (gradient) effect one, a little 俗态 prologue

With the growing support for CSS3, the gradual background effect of compatibility has become completely possible, and this article will show you how to implement a gradient background effect for compatibility. In many browsers, the Opera browser is not currently supported.

This example effect is the same effect, that is, the vertical gradient, the starting color red, the end color blue, the end of the blue transparency is 0.5.

Second, the gradient background under IE browser

The use of the gradient filter for IE is required using the gradient background of IE. The following code:

filter: Progid:DXImageTransform.Microsoft. Gradient (startcolorstr=Red,endcolorstr=Blue,gradienttype=1);

Related instructions:
The above filter code mainly has three parameters, in order:startcolorstr, endcolorstr, and GradientType.
Where gradienttype=1 represents a horizontal gradient ,gradienttype=0 represents a longitudinal transformation . startcolorstr= "Color " represents the starting color of the gradient gradient, andendcolorstr= "Color " represents the color at the end of the gradient.

The above code realizes the red to blue gradient, but does not contain the transparency change, this is because IE does not currently support the Opacity attribute and the Rgba color, to realize the change of transparency under IE, or the need to use IE filter, IE transparency Filter function is more powerful, This power is similar to the use of css-gradient background gradients in Firefox or Safari browsers. For example, use the following:

filter:Alpha(opacityfinishopacitystyle=1startx=0 ,starty=5,finishx=90,finishy=60)

The meanings of each of these parameters are as follows:
Opacity represents transparency, the default range is from 0 to 100, and they are actually in percent form. In other words, 0 is completely transparent and 100 is completely opaque.
Finishopacity is an optional parameter that you can use to specify the transparency at the end if you want to set the transparency effect of the gradient. The range is also 0 to 100.
Style is used to specify the shape characteristics of transparent areas:
0 for Unified shape
1 for linear
2 Stands for radial
3 represents the rectangle.
StartX The x-coordinate at the beginning of the gradient transparency effect.
Starty the y-coordinate at the beginning of the gradient transparency effect.
Finishx The x-coordinate at the end of the gradient transparency effect.
Finishy the y-coordinate at the end of the gradient transparency effect.

To achieve this, the code for the vertical gradient of red and blue with transparency changes under IE is as follows:

. gradient{  width:300px; height:150px;  Filter:alpha (opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) Progid:D XImageTransform.Microsoft.gradient (startcolorstr=red,endcolorstr=blue,gradienttype=1);  -ms-filter:alpha (opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) Progid:D XImageTransform.Microsoft.gradient (startcolorstr=red,endcolorstr=blue,gradienttype=1);} <div class= "Gradient" ></div>

Results such as:

Third, the background of the gradient under the Firefox browser

For the implementation of the Firefox 3.6+ gradient background, you need to use the CSS3 gradient property,-moz-linear-gradient property, In the previous article I described in detail the implementation of Firefox3.6 under the gradient background, you are interested can be ruthlessly click here: CSS gradient CSS3 gradient in the use of Firefox3.6. I'm not going to go into specifics here, but for the implementation of the effect you mentioned at the beginning of this article, see the following code:

. gradient{    width:300px;    height:150px;    Background:-moz-linear-gradient (top, Red, RGBA (0, 0, 255, 0.5));  } <div class= "Gradient" ></div>

The effect of this code under the Firefox3.6 browser is:

Four, Chrome/safari browser under the gradient background implementation

For the WebKit Core browser, such as the Chrome/safari browser under the gradient background of the implementation is also using the CSS3 gradient method, css-gradient, specifically-webkit-gradient, so the term Firefox browser there are some differences. I have a very detailed introduction to this in the previous article, you can click here: CSS gradient gradient WebKit core browser use. The specific use is not detailed, see the following code:

. gradient{    width:300px;    height:150px;    Background:-webkit-gradient (linear, 0 0, 0 bottom, from (#ff0000), to (RGBA (0, 0, 255, 0.5)));  } <div class= "Gradient" ></div>

The effect of this code in the Safari 4 browser is:

Added on 2011-04-07
The OPERA11 also supports CSS3 gradients. It uses a prefix that is consistent with Firefox and needs to be used -o- . In addition, Chrome's gradient usage is beginning to move closer to the usage of Firefox's browser.

V. Synthesis – the gradient background effect of compatibility

The relevant code is as follows:

. gradient{    width:300px;    height:150px;    Filter:alpha (opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) Progid:D XImageTransform.Microsoft.gradient (startcolorstr=red,endcolorstr=blue,gradienttype=0);    -ms-filter:alpha (opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) Progid:D XImageTransform.Microsoft.gradient (startcolorstr=red,endcolorstr=blue,gradienttype=0);/*ie8*/    background: Red /* Some browsers that do not support background gradients *      /background:-moz-linear-gradient (top, Red, RGBA (0, 0, 255, 0.5));      Background:-webkit-gradient (linear, 0 0, 0 bottom, from (#ff0000), to (RGBA (0, 0, 255, 0.5)));      Background:-o-linear-gradient (top, Red, RGBA (0, 0, 255, 0.5)); }<div class= "Gradient" ></div>

The results are the above three categories respectively.
You can ruthlessly click here: Compatibility gradient Background effect Demo

Vi. Conclusion

The potential of CSS3 is so great that the gradient can create a lot of superb UI effects that were previously only possible with images. The implementation of CSS gradient background can effectively reduce the number of pictures on the page, that is, to reduce the HTTP request, is very useful. But the Internet Explorer has been squatting on the side of the latrine gnawing at the chicken leg-the delicious, the use of high-resource filters to achieve the gradient effect. So, for the time being, the application of the gradient background has yet to be weighed against the pros and cons.

Day 161th: CSS3 gradient background (gradient) effect for compatibility

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.