參考文獻:http://caibaojian.com/css3-background-gradient.htmlcss
https://www.cnblogs.com/xzzzys/p/7495725.htmlhtml
目標:css3
一開始用 background: linear-gradient(to right, #000,#fff) :web
谷歌、火狐、歐朋(都是新版)能夠兼容chrome
ie9 不能夠兼容瀏覽器
因此爲了ie或其餘較低版本瀏覽器兼容:spa
.gradient{firefox
width: 973px;
height: 100%;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#000000), color-stop(100%,#ffffff)); /* 兼容Safari4-5, chrome1-9 */
background: -moz-linear-gradient(right, #000000 0%, #ffffff 100%); /* firefox */
background: -webkit-linear-gradient(left, #000000 0%,#ffffff 100%); /* chrome */
background: -o-linear-gradient(right, #000000 0%,#ffffff 100%); /* opera */
background: -ms-linear-gradient(right, #000000 0%,#ffffff 100%); /* ie */
background: linear-gradient(to right, #000000,#ffffff); /* firefox */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#ffffff',GradientType=1)"; /* 兼容IE8~IE9 */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ffffff',GradientType=1 ); /* 兼容IE5~IE9 */
}orm
注意:htm
一、filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ffffff',GradientType=1 ); 中 GradientType=1 表明水平 , GradientType=0 表明從上往下(默認從上往下)
還要特別值得注意的是 startColorstr='#000000' 中的 16進制顏色 不能簡寫 爲 #000 ,否則也不會識別達到效果
二、background: -webkit-linear-gradient(left, #000000 0%,#ffffff 100%); 中 left開始位置,其餘都都是結束位置
這樣就能夠兼容了。