CSS背景色漸變寫法兼容ie6至ie9
來源:易賢網(wǎng) 閱讀:8145 次 日期:2014-07-23 14:13:22
溫馨提示:易賢網(wǎng)小編為您整理了“CSS背景色漸變寫法兼容ie6至ie9”,方便廣大網(wǎng)友查閱!

最近在項目中,有很多地方都用到了線性漸變,比如:表單提交按鈕的背景,數(shù)據(jù)展示的標題背景等等,按照以前的做法是切 1px 圖片然后 repeat-x。下面我將介紹如何用 css 來完成該效果。

css3:linear-gradient

比如:黑色漸變到白色,代碼如下:

代碼如下:

.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%);

}

ie 濾鏡:filter

linear-gradient 在 ie9 以下是不支持的,所以對于 ie6 - ie8 我們可以使用濾鏡來解決,代碼如下:

代碼如下:

.gradient{

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

}

由于 filter 是 ie 的私有屬性,所以我們需要針對 ie9 單獨處理濾鏡效果,代碼如下:

代碼如下:

:root {filter:none;}

總結(jié):

綜上所述,線性漸變的兼容寫法如下:

代碼如下:

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;}

PS:

在實際的項目中,往往會碰到圓角和漸變的組合,如果使用上面的寫法,那么在 ie9 下會有 bug(在 ie9 下背景色不能完全切完),解決方法是SVG

更多信息請查看IT技術專欄

更多信息請查看網(wǎng)頁制作
易賢網(wǎng)手機網(wǎng)站地址:CSS背景色漸變寫法兼容ie6至ie9
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復僅供參考,敬請考生以權威部門公布的正式信息和咨詢?yōu)闇剩?/div>
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)