?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
<linear-gradient> = linear-gradient([ [ <angle> | to <side-or-corner> ] ,]? <color-stop>[, <color-stop>]+)
<side-or-corner> = [left | right] || [top | bottom]
<color-stop> = <color> [ <length> | <percentage> ]?
<angle>:用角度值指定漸變的方向(或角度)。
to left:設(shè)置漸變?yōu)閺挠业阶?。相?dāng)于: 270deg
to right:設(shè)置漸變從左到右。相當(dāng)于: 90deg
to top:設(shè)置漸變從下到上。相當(dāng)于: 0deg
to bottom:設(shè)置漸變從上到下。相當(dāng)于: 180deg。這是默認(rèn)值,等同于留空不寫(xiě)。
<color>:指定顏色。
<length>:用長(zhǎng)度值指定起止色位置。不允許負(fù)值
<percentage>:用百分比指定起止色位置。
如果想創(chuàng)建以對(duì)角線(xiàn)方式漸變的圖像,可以使用 to top left
這樣的多關(guān)鍵字方式來(lái)實(shí)現(xiàn)。
用默認(rèn)的漸變方向繪制一個(gè)最簡(jiǎn)單的線(xiàn)性漸變
示例代碼:
(圖一)
linear-gradient(#fff, #333); linear-gradient(to bottom, #fff, #333); linear-gradient(to top, #333, #fff); linear-gradient(180deg, #fff, #333); linear-gradient(to bottom, #fff 0%, #333 100%);
以上幾句代碼都可以實(shí)現(xiàn)如(圖一)的漸變效果
IE | Firefox | Chrome | Safari | Opera | iOS Safari | Android Browser | Android Chrome |
---|---|---|---|---|---|---|---|
6.0-9.0 #2 | 2.0-3.5 | 4.0-9.0 -webkit- #1 | 3.1-3.2 | 15.0+ | 3.2-4.3 -webkit- #1 | 2.1-3.0 -webkit- #1 | 10.0-25.0 -webkit- #1 |
10.0+ | 3.6-15.0 -moz- | 10.0-25.0 -webkit- | 4.0-5.0 -webkit- #1 | 5.0-6.1 | 4.0-4.3 -webkit- | 26.0+ | |
16.0+ | 26.0+ | 5.1-6.0 -webkit- | 7.0+ | 4.4+ | |||
6.1+ |
使用過(guò)時(shí)的語(yǔ)法:-webkit-gradient(linear,…)
IE6.0-9.0使用私有濾鏡來(lái)實(shí)現(xiàn)該效果: progid:DXImageTransform.Microsoft.Gradient()
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8" /> <title>linear-gradient()_CSS參考手冊(cè)_web前端開(kāi)發(fā)參考手冊(cè)系列</title> <meta name="author" content="Joy Du(飄零霧雨), dooyoe@gmail.com, www.doyoe.com" /> <style> div { width: 200px; height: 100px; margin-top: 10px; border: 1px solid #ddd; } .test { background: linear-gradient(#fff, #333); } .test2 { background: linear-gradient(#000, #f00 50%, #090); } .test3 { background: linear-gradient(0deg, #000 20%, #f00 50%, #090 80%); } .test4 { background: linear-gradient(45deg, #000, #f00 50%, #090); } .test5 { background: linear-gradient(to top right, #000, #f00 50%, #090); } </style> </head> <body> <div class="test"></div> <div class="test2"></div> <div class="test3"></div> <div class="test4"></div> <div class="test5"></div> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線(xiàn)實(shí)例