漸層
製作中的漸層:色標排在一條橫條上,目前選取的色標以取色器調整,並可設定類型、角度與中心點。
本頁內容
漸層編輯器用來製作漸層:色標排在一條橫條上,目前選取的色標以取色器調整,並可設定漸層的類型、角度與中心點。其中每個控制項都是元件庫本身的元件:取色器、用來設定色標位置的滑桿和數字欄位、用來選擇類型的分段控制項、用來設定角度的旋鈕,以及用來設定中心點的數字欄位。漸層本身加上的是色標橫條、預覽,以及讓這一切保持同步的 gradient 行為。
漸層
<div class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1"> <div class="gradient-preview" aria-hidden="true"></div> <div class="gradient-bar"></div> <div class="flex flex-wrap items-center gap-xs"> <button type="button" class="btn btn-sm gradient-add"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg>Add a stop </button> <button type="button" class="btn btn-sm gradient-remove"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg>Remove </button> <button type="button" class="btn btn-sm btn-quiet gradient-reverse"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M8 1.6667L8 14.3333" /><path d="M5.6667 6.3298L5.6667 11.45A0.55 0.55 0 0 1 5.1167 12L2.5566 12A0.55 0.55 0 0 1 2.0647 11.204L4.6248 6.0839A0.55 0.55 0 0 1 5.6667 6.3298Z" /><path d="M10.3333 6.3298L10.3333 11.45A0.55 0.55 0 0 0 10.8833 12L13.4434 12A0.55 0.55 0 0 0 13.9353 11.204L11.3752 6.0839A0.55 0.55 0 0 0 10.3333 6.3298Z" /> </svg>Reverse </button> </div> <div class="gradient-fields"> <fieldset class="gradient-color"> <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50"> <div class="color-picker-area"> <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div> </div> <span class="swatch swatch-lg color-picker-swatch"></span> <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue"> <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity"> <div class="color-picker-fields"> <select class="select select-sm color-picker-format" aria-label="Format"> <option value="hex" selected>Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off"> </div> </div> </fieldset> <div class="flex flex-col gap-md min-w(0)"> <fieldset class="gradient-offset"> <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop"> <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent"> </fieldset> <fieldset class="gradient-type"> <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div class="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic </label> </div> </fieldset> <div class="flex flex-wrap items-start gap-lg"> <fieldset class="gradient-angle"> <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135"> <span class="dial-value">135°</span> <span class="dial-thumb"></span> </div> </fieldset> <fieldset class="gradient-center"> <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent"> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent"> </fieldset> </div> </div> </div> <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' }] } })})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach, gradient } from '@master/ui/behaviors'import PlusIcon from '@master/icons-react/native/16/soft/plus'import MinusIcon from '@master/icons-react/native/16/soft/minus'import FlipHorizontalIcon from '@master/icons-react/native/16/soft/flip-horizontal'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => { const detach = [ attach(root.current!), gradient(document.getElementById('sunrise')!, { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' } ] } }), ] return () => detach.forEach(stop => stop()) }, []) return ( <div ref={root} className="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style={{ '--gradient-ratio': '3 / 1' } as React.CSSProperties}> <div className="gradient-preview" aria-hidden="true"></div> <div className="gradient-bar"></div> <div className="flex flex-wrap items-center gap-xs"> <button type="button" className="btn btn-sm gradient-add"> <PlusIcon className="icon" />Add a stop </button> <button type="button" className="btn btn-sm gradient-remove"> <MinusIcon className="icon" />Remove </button> <button type="button" className="btn btn-sm btn-quiet gradient-reverse"> <FlipHorizontalIcon className="icon" />Reverse </button> </div> <div className="gradient-fields"> <fieldset className="gradient-color"> <legend className="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div className="color-picker" style={{ '--color-picker-lightness': '.7', '--color-picker-chroma': '.19', '--color-picker-hue': '50' } as React.CSSProperties}> <div className="color-picker-area"> <div className="color-picker-thumb" role="slider" tabIndex={0} aria-label="Lightness and chroma" aria-valuemin={0} aria-valuemax={100} aria-valuenow={70}></div> </div> <span className="swatch swatch-lg color-picker-swatch"></span> <input type="range" className="slider color-picker-hue" min="0" max="360" defaultValue="50" aria-label="Hue" /> <input type="range" className="slider color-picker-alpha" min="0" max="100" defaultValue="100" aria-label="Opacity" /> <div className="color-picker-fields"> <select className="select select-sm color-picker-format" aria-label="Format" defaultValue="hex"> <option value="hex">Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input className="input input-sm color-picker-text" defaultValue="#ff6a00" aria-label="Color" spellCheck="false" autoComplete="off" /> </div> </div> </fieldset> <div className="flex flex-col gap-md min-w(0)"> <fieldset className="gradient-offset"> <legend className="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" className="slider" min="0" max="100" step="1" defaultValue="0" aria-label="Position of the stop" /> <input type="number" className="input input-sm w(72)" min="0" max="100" step="1" defaultValue="0" aria-label="Position of the stop, in percent" /> </fieldset> <fieldset className="gradient-type"> <legend className="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div className="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label className="segmented-item"> <input type="radio" className="segmented-input" name="sunrise-type" value="linear" defaultChecked />Linear </label> <label className="segmented-item"> <input type="radio" className="segmented-input" name="sunrise-type" value="radial" />Radial </label> <label className="segmented-item"> <input type="radio" className="segmented-input" name="sunrise-type" value="conic" />Conic </label> </div> </fieldset> <div className="flex flex-wrap items-start gap-lg"> <fieldset className="gradient-angle"> <legend className="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div className="dial dial-sm dial-full" role="slider" tabIndex={0} aria-label="Angle" aria-valuenow={135} aria-valuemin={0} aria-valuemax={360} aria-valuetext="135°" style={{ '--dial-value': '135' } as React.CSSProperties}> <span className="dial-value">135°</span> <span className="dial-thumb"></span> </div> </fieldset> <fieldset className="gradient-center"> <legend className="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" className="input input-sm w(72)" min="0" max="100" defaultValue="50" aria-label="Center across, in percent" /> <input type="number" className="input input-sm w(72)" min="0" max="100" defaultValue="50" aria-label="Center down, in percent" /> </fieldset> </div> </div> </div> <pre className="code-block gradient-css" role="region" tabIndex={0} aria-label="The gradient as CSS">{``}</pre> </div> )}<script> import { attach, gradient } from '@master/ui/behaviors' import PlusIcon from '@master/icons-svelte/native/16/soft/plus' import MinusIcon from '@master/icons-svelte/native/16/soft/minus' import FlipHorizontalIcon from '@master/icons-svelte/native/16/soft/flip-horizontal' function mounted(root) { const detach = [ attach(root), gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' } ] } }), ] return () => detach.forEach(stop => stop()) }</script><div class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1" {@attach mounted}> <div class="gradient-preview" aria-hidden="true"></div> <div class="gradient-bar"></div> <div class="flex flex-wrap items-center gap-xs"> <button type="button" class="btn btn-sm gradient-add"> <PlusIcon class="icon" />Add a stop </button> <button type="button" class="btn btn-sm gradient-remove"> <MinusIcon class="icon" />Remove </button> <button type="button" class="btn btn-sm btn-quiet gradient-reverse"> <FlipHorizontalIcon class="icon" />Reverse </button> </div> <div class="gradient-fields"> <fieldset class="gradient-color"> <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50"> <div class="color-picker-area"> <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div> </div> <span class="swatch swatch-lg color-picker-swatch"></span> <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue"> <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity"> <div class="color-picker-fields"> <select class="select select-sm color-picker-format" aria-label="Format"> <option value="hex" selected>Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off"> </div> </div> </fieldset> <div class="flex flex-col gap-md min-w(0)"> <fieldset class="gradient-offset"> <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop"> <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent"> </fieldset> <fieldset class="gradient-type"> <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div class="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic </label> </div> </fieldset> <div class="flex flex-wrap items-start gap-lg"> <fieldset class="gradient-angle"> <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135"> <span class="dial-value">135°</span> <span class="dial-thumb"></span> </div> </fieldset> <fieldset class="gradient-center"> <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent"> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent"> </fieldset> </div> </div> </div> <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, gradient } from '@master/ui/behaviors'import PlusIcon from '@master/icons-vue/native/16/soft/plus'import MinusIcon from '@master/icons-vue/native/16/soft/minus'import FlipHorizontalIcon from '@master/icons-vue/native/16/soft/flip-horizontal'const root = ref(null)let detach = []onMounted(() => { detach = [ attach(root.value), gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' } ] } }), ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template> <div ref="root" class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1"> <div class="gradient-preview" aria-hidden="true"></div> <div class="gradient-bar"></div> <div class="flex flex-wrap items-center gap-xs"> <button type="button" class="btn btn-sm gradient-add"> <PlusIcon class="icon" />Add a stop </button> <button type="button" class="btn btn-sm gradient-remove"> <MinusIcon class="icon" />Remove </button> <button type="button" class="btn btn-sm btn-quiet gradient-reverse"> <FlipHorizontalIcon class="icon" />Reverse </button> </div> <div class="gradient-fields"> <fieldset class="gradient-color"> <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50"> <div class="color-picker-area"> <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div> </div> <span class="swatch swatch-lg color-picker-swatch"></span> <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue"> <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity"> <div class="color-picker-fields"> <select class="select select-sm color-picker-format" aria-label="Format"> <option value="hex" selected>Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off"> </div> </div> </fieldset> <div class="flex flex-col gap-md min-w(0)"> <fieldset class="gradient-offset"> <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop"> <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent"> </fieldset> <fieldset class="gradient-type"> <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div class="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic </label> </div> </fieldset> <div class="flex flex-wrap items-start gap-lg"> <fieldset class="gradient-angle"> <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135"> <span class="dial-value">135°</span> <span class="dial-thumb"></span> </div> </fieldset> <fieldset class="gradient-center"> <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent"> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent"> </fieldset> </div> </div> </div> <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre> </div></template>#值
漸層是由四個部分組成的值:
| 部分 | 內容 |
|---|---|
type | linear、radial 或 conic |
angle | 角度(度),用於線性與圓錐漸層 |
center | 兩個百分比,用於放射與圓錐漸層 |
stops | 每個色標都有一個固定跟著它的 id、從 0 到 100 的 offset,以及一個 color |
色彩的寫法與取色器相同,以十六進位的 sRGB 表示,並包含不透明度。gradientCss(value) 會將漸層寫成 CSS,預覽和複製的文字都來自它:在能指定插值色彩空間的瀏覽器中以 OKLab 插值,並在前面先寫一行供不支援的瀏覽器使用的備援。
background-image: linear-gradient(90deg, #ff6a00 0%, #ee0979 100%);background-image: linear-gradient(in oklab 90deg, #ff6a00 0%, #ee0979 100%);編輯器不會讀回 CSS:值由編輯器保存,應用程式也應儲存值,而不是文字。
#色標
- 色標的控點是一個滑桿,代表它的位置,在橫條上以該色標顏色的圓盤呈現。按下即可選取色標,拖曳可移動它;方向鍵每次移動 1,按住 Shift 時每次移動 10,Home 和 End 則移到兩端。目前選取的色標帶有
aria-current="true",會略微突出,並加上以文字色繪製的外環。 - 色標可以越過彼此。 將色標移過另一個色標時,移動的色標會保留原有的 id,控點也會保留焦點;漸層會依位置的順序繪製色標。兩個色標位於同一位置時會形成銳利的邊界,並維持原本的順序。
- 新增會在目前色標之後 10 個單位處(最多到 100)加入一個與目前色標同色的色標。以按鈕或 Delete 移除色標時,焦點會交給橫條上的下一個色標,若沒有則交給前一個。至少需要兩個色標:只剩兩個時,無法再移除。
- 反轉會將色標的順序顛倒:每個位置都變成 100 減去原本的值。
拖曳從來不是唯一的操作方式:位置有滑桿和旁邊的數字欄位,每個色標也都能以 Tab 抵達。
#狀態
在根元素上設定 aria-readonly="true" 表示漸層無法變更,設定 aria-disabled="true" 則表示漸層目前未使用:控點停留在原位,控制項則會停用。
#行為
import { gradient, gradientCss } from '@master/ui/behaviors/gradient.js'const editor = gradient(document.querySelector('.gradient'), { value: { type: 'linear', angle: 90, center: [50, 50], stops: [ { id: 'from', offset: 0, color: '#ff6a00' }, { id: 'to', offset: 100, color: '#ee0979' }, ] },})editor.value // the value as abovegradientCss(editor.value).text // the two lines to copy使用者操作期間會持續觸發 input,操作結束時觸發 change;設定 value 會顯示另一個漸層,但不會觸發任何事件。行為會依值寫出控點,因此自行寫出控點的框架應提供 draw。它會在根元素上以 --gradient 和 --gradient-fallback 公開漸層,並在每個色標的控點上以 --gradient-offset 和 --gradient-color 公開該色標:編輯器繪製的是它的內容,樣式表則負責定位。
#鍵盤
| 按鍵 | 動作 |
|---|---|
| Tab | 移到橫條上的目前色標,再依序移過各個控制項;其他色標可以用指標選取,或從橫條在 Tab 順序中的位置抵達 |
| ArrowRight, ArrowUp | 在色標上:朝終點移動 1 個單位;按住 Shift 時移動 10 個單位。頁面由右至左排列時,ArrowRight 會向左移動 |
| ArrowLeft, ArrowDown | 在色標上:朝起點移動 1 個單位;按住 Shift 時移動 10 個單位 |
| PageUp, PageDown | 在色標上:移動 10 個單位 |
| Home, End | 在色標上:移到 0 或 100 |
| Delete, Backspace | 在色標上:色標多於兩個時將它移除,並將焦點交給相鄰的色標 |
#無障礙
- 每個控點都以它在色標中的順序命名,並在
aria-valuetext中說明它的位置與色彩。 - 預覽只是值的圖像:請將它從輔助技術中隱藏,因為色標和 CSS 已傳達相同的資訊。
- 在強制色彩模式下,漸層會保留自己的色彩,因為這些色彩就是它的內容;控點和橫條則以系統色彩繪製輪廓。
#React、Svelte 和 Vue
gradient 元件依值寫出控點與控制項,並掛上行為。使用 npx master-ui add gradient 將它複製到專案中;React、Svelte 和 Vue 說明了這些元件的建構與使用方式。
#類別
| 類別 | 說明 |
|---|---|
gradient | 編輯器:預覽、色標橫條和控制項。gradient 行為會寫出色標的控點並公開漸層。在其上標記 aria-readonly="true" 或 aria-disabled="true" 可防止變更 |
gradient-preview | 棋盤格背景上的漸層,除非 --gradient-ratio 另有設定,否則比例為 16 : 9;請以 aria-hidden 隱藏它,因為色標和 CSS 已傳達相同的資訊 |
gradient-bar | 不論類型為何,都由起點到終點排列色標,呈現為一道讓控點立於其上的淺凹槽 |
gradient-stop | 由行為寫出的色標控點:沿橫條位於 --gradient-offset 處、帶珍珠色外環的色標色圓盤,也是代表位置的滑桿,並以它在色標中的順序命名 |
gradient-fields | 控制項,排成一欄;空間足夠時並排成兩欄 |
gradient-color | 容納目前色標的 color-picker;gradient 行為會掛上取色器 |
gradient-offset | 容納一個範圍滑桿和一個數字輸入欄位,範圍從 0 到 100,用於目前色標的位置 |
gradient-type | 容納選擇類型的 linear、radial 和 conic 單選按鈕;是一個分段控制項 |
gradient-angle | 容納設定角度的旋鈕,範圍從 0 到 360 度,用於線性與圓錐漸層 |
gradient-center | 容納兩個數字輸入欄位,即中心點的 x 和 y(百分比),用於放射與圓錐漸層 |
gradient-add | 在目前色標之後 10 個單位處加入一個同色的色標,最多到 100 |
gradient-remove | 移除目前色標;只剩兩個色標時停用 |
gradient-reverse | 反轉色標的順序 |
gradient-css | 由行為寫出、可供複製的 CSS 漸層:先是備援,再是以 OKLab 插值的那一行 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--gradient | none | 以 OKLab 插值的漸層,由行為寫出 |
--gradient-fallback | none | 以 sRGB 插值的漸層,供無法指定插值方式的瀏覽器使用 |
--gradient-bar | 橫條的填色:不論漸層類型,都把每個色標從起點到終點畫成以 sRGB 插值的直線漸層,由行為寫出設定於 gradient | |
--gradient-ratio | 預覽的形狀;預設為 16 / 9設定於 gradient-preview | |
--gradient-offset | 控點在橫條上的位置,從 0 到 100,由行為寫出設定於 gradient-stop | |
--gradient-color | 控點所屬色標的色彩,由行為寫出設定於 gradient-stop |
#相關內容
- 顏色選擇器可選擇任何顏色:在明度與彩度的平面上點選,調整色相與不透明度,或直接輸入。
- 旋鈕沿著圓周轉動滑塊來設定數值,例如以旋鈕方式調整的程度、角度或方向。
- 滑桿原生範圍輸入控制項,搭配纖細的凹槽和珍珠般的滑塊。
- 分段控制項在同一條軌道上排列數個選項,選取指示會滑到目前的選項。
- 色票以帶細緻邊緣的圓形色票顯示或選取顏色。