CSS3中關於“漸層”相容性解決方案詳解

來源:互聯網
上載者:User
  這次是簡單的談一下我們常見的漸層在各個瀏覽器下的相容性問題,算一個比較簡單的問題。
 我們熟知的瀏覽器有Chrome、Firefox、Opera、Safari以及ie系列。最基礎的background:#cccccc屬性工作表示頁面呈現#cccccc色,當然這個在任何瀏覽器下面都是滿足的。但是隨著我們對顏色要求的提高,引入了漸層linear-gradient,不同的瀏覽器對於它的認知需要加不同的首碼。通過上面的例子我們可以知道firefox:-moz-、chrome/safari/opera:-webkit-、ie:-ms-、當然ie很多版本都不接受,於是可以採取濾鏡的方式處理。
重點說明一下ie的濾鏡效果:

filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150)progid:DXImageTransform.Microsoft.gradient(startcolorstr=#ffffff,endcolorstr=#000000,gradientType=0);-ms-filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) progid:DXImageTransform.Microsoft.gradient(startcolorstr=#ffffff,endcolorstr=#000000,gradientType=0);

style=0:統一形狀;style=1:線性;style=2:放射狀;style=3:矩形;
startx/starty/finishx/finishy:起始和終點的座標;
gradient=1:橫向漸層;gradient=0:縱向漸層。

-webkit-linear-gradient(top,#ffffff,#000000);
linear:漸層類型
top:起始點
#ffffff:起始顏色
#000000:終點顏色
支援瀏覽器:Webkit(-webkit-),Gecko(-moz-),presto(-o-),Trident(-ms-)
方向:
上文中'top'為起始點,同時也蘊含'to bottom'
<angle>:0deg表示方向從左至右,90deg表示方向從下向上。可用負值表示,與正值相反方向。
top類:給予起始方向便可。兩個方向的只要加上兩方向屬性,如left top。

ps:其他的不滿足這些變化的瀏覽器還是比較少的。對於這種情況可以採取定義一個適合的過度色用最基本的background:#red之類的表示。

相關文章

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.