CSS3 漸變分線性(linear-gradient)與徑向(radial-gradient),均為圖像值,可用於任何接受 <image> 的屬性(background、border-image、mask 等)。
/* 標準語法 */
background: linear-gradient(方向, 顏色停靠點...);
/* 方向關鍵字 */
to right / to left / to top / to bottom / to top right 等
/* 角度 */
45deg / -90deg
/* 顏色停靠點 */
red, orange 50%, yellow 75%, green
範例:linear-gradient(45deg, #ff0000, #ffff00, #00ff00)
/* 標準語法 */
background: radial-gradient(形狀 大小 at 位置, 顏色停靠點...);
/* 形狀 */ circle | ellipse
/* 大小 */ closest-side | farthest-corner | 具體長度 | 百分比
/* 位置 */ center | top left | 50% 50% 等
範例:radial-gradient(circle farthest-corner at center, #fff, #00f)
repeating-linear-gradient(45deg, red, red 10px, blue 10px, blue 20px);
repeating-radial-gradient(circle at center, red, red 10px, blue 10px, blue 20px);
-webkit-、-moz-、-o-、-ms- 前綴,建議用 Autoprefixer 自動處理。(原文附有測試頁截圖,此處略)
background-clip: text)、Loading 動畫。