opacity
opacity 屬性指定一個物件或一組物件的透明度,即背景被元素遮蓋的程度。
注意: 作為演示屬性,opacity 也有一個對應的 CSS 屬性:opacity。當同時指定兩者時,CSS 屬性具有更高的優先順序。
你可以將此屬性與以下 SVG 元素一起使用
<a><circle><ellipse><foreignObject><g><image><line><marker><path><polygon><polyline><rect><svg><switch><symbol><text><textPath><tspan><use>
與分別應用於單個操作並在元素渲染時渲染的 fill-opacity、stroke-opacity 和 stop-opacity 不同,opacity 應用於整個物件或組,更像是一種對物件或組渲染影像的後處理操作。因此,當同一區域同時具有 opacity 和其他不透明度屬性時,它們會疊加在一起,導致不透明度相乘。
示例
html
<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="0" y2="100%">
<stop offset="0%" stop-color="skyblue" />
<stop offset="100%" stop-color="seagreen" />
</linearGradient>
</defs>
<rect x="0" y="0" width="100%" height="100%" fill="url(#gradient)" />
<circle cx="50" cy="50" r="40" fill="black" />
<circle cx="150" cy="50" r="40" fill="black" opacity="0.3" />
</svg>
用法說明
| 預設值 | 1 |
|---|---|
| 值 | <alpha-value> |
| 可動畫的 | 是 |
<alpha-value>-
應用於整個物件的統一不透明度設定,為
<number>型別。任何超出 0.0(完全透明)到 1.0(完全不透明)範圍的值將被裁剪到此範圍內。
規範
| 規範 |
|---|
| CSS 顏色模組第四版 # propdef-opacity |
| Scalable Vector Graphics (SVG) 2 # ObjectAndGroupOpacityProperties |
瀏覽器相容性
載入中…