color

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

color 属性用来为 fill 属性、stroke 属性、stop-color 属性、flood-color 属性和 lighting-color 属性提供一个潜在的间接值(currentColor)。

作为一个外观属性,它还可以直接用作 CSS 样式表的属性。请阅读 CSS color 以了解更多信息。

使用说明

类别 外观属性
<color> | inherit
规范文档 SVG 1.1 (2nd Edition)

示例

html
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g color="green">
    <rect width="50" height="50" fill="currentColor" />
    <circle
      r="25"
      cx="70"
      cy="70"
      stroke="currentColor"
      fill="none"
      stroke-width="5" />
  </g>
</svg>

元素

规范

Specification
Scalable Vector Graphics (SVG) 2
# ColorProperty

浏览器兼容性

BCD tables only load in the browser