fill - SVG: Scalable Vector Graphics 编辑

The fill attribute has two different meanings. For shapes and text it's a presentation attribute that defines the color (or any SVG paint servers like gradients or patterns) used to paint the element; for animation it defines the final state of the animation.

As a presentation attribute, it can be applied to any element but it only has an effect on the following eleven elements: <altGlyph>, <circle>, <ellipse>, <path>, <polygon>, <polyline>, <rect>, <text>, <textPath>, <tref>, and <tspan>.

For animation five elements are using this attribute: <animate>, <animateColor>, <animateMotion>, <animateTransform>, and <set>.

html,body,svg { height:100% }
<svg viewBox="0 0 300 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Simple color fill -->
  <circle cx="50" cy="50" r="40" fill="pink" />

  <!-- Fill circle with a gradient -->
  <defs>
    <radialGradient id="myGradient">
      <stop offset="0%"   stop-color="pink" />
      <stop offset="100%" stop-color="black" />
    </radialGradient>
  </defs>

  <circle cx="150" cy="50" r="40" fill="url(#myGradient)" />

  <!--
  Keeping the final state of an animated circle
  which is a circle with a radius of 40.
  -->
  <circle cx="250" cy="50" r="20">
    <animate attributeType="XML"
             attributeName="r"
             from="0" to="40" dur="5s"
             fill="freeze" />
  </circle>
</svg>

altGlyph

Warning: As of SVG2 <altGlyph> is deprecated and shouldn't be used.

For <altGlyph>, fill is a presentation attribute that defines the color of the glyph.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

animate

For <animate>, fill defines the final state of the animation.

Valuefreeze (Keep the state of the last animation frame) | remove (Keep the state of the first animation frame)
Default valueremove
AnimatableNo

animateColor

Warning: As of SVG Animation 2 <animateColor> is deprecated and shouldn't be used. Use <animate> instead.

For <animateColor>, fill defines the final state of the animation.

Valuefreeze (Keep the state of the last animation frame) | remove (Keep the state of the first animation frame)
Default valueremove
AnimatableNo

animateMotion

For <animateMotion>, fill defines the final state of the animation.

Valuefreeze (Keep the state of the last animation frame) | remove (Keep the state of the first animation frame)
Default valueremove
AnimatableNo

animateTransform

For <animateTransform>, fill defines the final state of the animation.

Valuefreeze (Keep the state of the last animation frame) | remove (Keep the state of the first animation frame)
Default valueremove
AnimatableNo

circle

For <circle>, fill is a presentation attribute that defines the color of the circle.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

ellipse

For <ellipse>, fill is a presentation attribute that defines the color of the ellipse.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

path

For <path>, fill is a presentation attribute that defines the color of the interior of the shape. (Interior is define by the fill-rule attribute)

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

polygon

For <polygon>, fill is a presentation attribute that defines the color of the interior of the shape. (Interior is define by the fill-rule attribute)

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

polyline

For <polyline>, fill is a presentation attribute that defines tthe color of the interior of the shape. (Interior is define by the fill-rule attribute)

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

rect

For <rect>, fill is a presentation attribute that defines the color of the rectangle.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

set

For <set>, fill defines the final state of the animation.

Valuefreeze (Keep the state of the last animation frame) | remove (Keep the state of the first animation frame)
Default valueremove
AnimatableNo

text

For <text>, fill is a presentation attribute that defines what the color of the text.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

textPath

For <textPath>, fill is a presentation attribute that defines the color of the text.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

tref

Warning: As of SVG2 <tref> is deprecated and shouldn't be used.

For <tref>, fill is a presentation attribute that defines the color of the text.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

tspan

For <tspan>, fill is a presentation attribute that defines the color of the text.

Value<paint>
Default valueblack
AnimatableYes

Note: As a presentation attribute fill can be used as a CSS property.

Specifications

SpecificationStatusComment
SVG Animations Level 2
The definition of 'transform' in that specification.
Editor's DraftDefinition for animations
Scalable Vector Graphics (SVG) 2
The definition of 'fill' in that specification.
Candidate RecommendationDefinition for shapes and texts.
Adds context-fill and context-stroke.
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'fill' in that specification.
RecommendationInitial definition for animations
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'fill' in that specification.
RecommendationInitial definition for shapes and texts

Browser compatibility

BCD tables only load in the browser

Note: For information on using the context-fill (and context-stroke) values from HTML documents, see the documentation for the non-standard -moz-context-properties property.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:50 次

字数:17994

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文