<linearGradient> - SVG: Scalable Vector Graphics 编辑

The <linearGradient> element lets authors define linear gradients that can be applied to fill or stroke of graphical elements.

Don't be confused with CSS linear-gradient() as CSS gradients can only apply to HTML elements where SVG gradient can only apply to SVG elements.

html,body,svg { height:100% }
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <linearGradient id="myGradient" gradientTransform="rotate(90)">
      <stop offset="5%"  stop-color="gold" />
      <stop offset="95%" stop-color="red" />
    </linearGradient>
  </defs>

  <!-- using my linear gradient -->
  <circle cx="5" cy="5" r="4" fill="url('#myGradient')" />
</svg>

Attributes

gradientUnits
This attribute defines the coordinate system for attributes x1, x2, y1, y2
Value typeuserSpaceOnUse|objectBoundingBox ; Default value: objectBoundingBox; Animatableyes
gradientTransform
This attribute provides additional transformation to the gradient coordinate system.
Value type: <transform-list> ; Default value: identity transform; Animatableyes
href
This attribute defines a reference to another <linearGradient> element that will be used as a template.
Value type: <URL> ; Default value: none; Animatable: yes
spreadMethod
This attribute indicates how the gradient behaves if it starts or ends inside the bounds of the shape containing the gradient.
Value type: pad|reflect|repeat ; Default value: pad; Animatableyes
x1
This attribute defines the x coordinate of the starting point of the vector gradient along which the linear gradient is drawn.
Value type: <length> ; Default value: 0%; Animatable: yes
x2
This attribute defines the x coordinate of the ending point of the vector gradient along which the linear gradient is drawn.
Value type: <length> ; Default value: 100%; Animatable: yes
xlink:href

Deprecated since SVG 2

This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

An <IRI> reference to another <linearGradient> element that will be used as a template.
Value type: <IRI> ; Default value: none; Animatable: yes
y1
This attribute defines the y coordinate of the starting point of the vector gradient along which the linear gradient is drawn.
Value type: <length> ; Default value: 0%; Animatable: yes
y2
This attribute defines the y coordinate of the ending point of the vector gradient along which the linear gradient is drawn.
Value type: <length> ; Default value: 0%; Animatable: yes

Global attributes

Core Attributes
Most notably: id
Styling Attributes
class, style
Event Attributes
Global event attributes, Document element event attributes
Presentation Attributes
Most notably: clip-path, clip-rule, color, color-interpolation, color-rendering, cursor, display, fill, fill-opacity, fill-rule, filter, mask, opacity, pointer-events, shape-rendering, stroke, stroke-dasharray, stroke-dashoffset, stroke-linecap, stroke-linejoin, stroke-miterlimit, stroke-opacity, stroke-width, transform, vector-effect, visibility
XLink Attributes
xlink:href, xlink:title

Usage notes

CategoriesGradient element
Permitted contentAny number of the following elements, in any order:
Descriptive elements
<animate>, <animateTransform>, <set>, <stop>

Specifications

SpecificationStatusComment
Scalable Vector Graphics (SVG) 2
The definition of '<linearGradient>' in that specification.
Candidate Recommendation 
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of '<linearGradient>' in that specification.
RecommendationInitial definition

Browser compatibility

BCD tables only load in the browser

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

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

发布评论

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

词条统计

浏览:73 次

字数:11302

最后编辑:7 年前

编辑次数:0 次

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