css background color gradient compatible writing method_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:43:41
Original
1058 people have browsed it

css3: linear-gradient

For example: black gradient to white, the code is as follows:

.gradient{    background: -moz-linear-gradient(top, #000000 0%, #ffffff 100%);    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#ffffff));    background: -webkit-linear-gradient(top, #000000 0%,#ffffff 100%);    background: -o-linear-gradient(top, #000000 0%,#ffffff 100%);    background: -ms-linear-gradient(top, #000000 0%,#ffffff 100%);    background: linear-gradient(to bottom, #000000 0%,#ffffff 100%);}
Copy after login

Instructions: Linear-gradient click here for specific usage.

ie filter: filter

linear-gradient is not supported below ie9, so for ie6 - ie8 we can use filters to solve the problem, the code is as follows:

.gradient{    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ffffff',GradientType=0 );}
Copy after login

Since filter is a private attribute of ie, we need to handle the filter effect separately for ie9. The code is as follows:

:root {filter:none;}
Copy after login

Summary:

To sum up, the compatible writing methods of linear gradient are as follows:

.gradient{    background: #000000;    background: -moz-linear-gradient(top,  #000000 0%, #ffffff 100%);    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#ffffff));    background: -webkit-linear-gradient(top,  #000000 0%,#ffffff 100%);    background: -o-linear-gradient(top,  #000000 0%,#ffffff 100%);    background: -ms-linear-gradient(top,  #000000 0%,#ffffff 100%);    background: linear-gradient(to bottom,  #000000 0%,#ffffff 100%);    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ffffff',GradientType=0 );}:root .gradient{filter:none;}
Copy after login

PS:

In actual projects, we often encounter the combination of rounded corners and gradients. If you use the above writing method, there will be bugs under ie9 ( The background color cannot be completely cut out under IE9), the solution is SVG, click here for details.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template