根據caniuse(http://caniuse.com/#search=gradient),rgba相容性為IE10以及以上瀏覽器。
執行個體代碼:
<!doctype html><html> <head> <meta charset="UTF-8" /> <title>gradient 相容性處理</title> <style type="text/css"> * { margin: 0; padding: 0; } .parent { width: 400px; height: 400px; margin: 100px; font-size: 20px; color: #FF0000; border: 1px solid red; 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%); } </style> </head> <body> <div> </div> </body></html>
chrome瀏覽器效果:
IE8瀏覽器效果(無漸層):
rgba相容性處理:
.parent { width: 400px; height: 400px; margin: 100px; font-size: 20px; color: #FF0000; border: 1px solid red; 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); }
設定filter屬性目的是上一行的透明度不起作用的時候執行,filter: progid:DXImageTransform.Microsoft.gradient是用來做漸層的,GradientType:可讀寫,設定或檢索色彩漸層的方向:
1:預設值。水平漸層。
0:垂直漸層。
總結:至此完成IE9以及以下IE瀏覽器gradient相容性處理。