dx - SVG: Scalable Vector Graphics 编辑

The dx attribute indicates a shift along the x-axis on the position of an element or its content.

Seven elements are using this attribute: <altGlyph>, <feDropShadow>, <feOffset>, <glyphRef>, <text>, <tref>, and <tspan>

html,body,svg { height:100% }
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Lines materialized the position of the glyphs -->
  <line x1="0"  x2="100%" y1="50%" y2="50%" />
  <line x1="10%" x2="10%" y1="0"   y2="100%" />
  <line x1="60%" x2="60%" y1="0"   y2="100%" />

  <!-- Some reference text -->
  <text x="10%" y="50%" fill="grey">SVG</text>

  <!-- The same text with a shift along the x-axis -->
  <text dx="50%" x="10%" y="50%">SVG</text>
</svg>
line {
  stroke: red;
  stroke-width: .5px;
  stroke-dasharray: 3px;
}

altGlyph

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

For <altGlyph>, if it contains a single value, dx defines a shift along the x-axis for all alternate glyph.

If there are multiple values, dx defines a shift along the x-axis for each individual glyph relative to the preceding glyph. If there are less values than glyphs, the remaining glyphs use a value of 0. If there are more values than glyphs, extra values are ignored.

ValueList of <length>
Default valuenone
AnimatableYes

feDropShadow

For <feDropShadow>, dx defines the x offset of the droped shadow. The unit used to resolve the value of the attribute is set by the primitiveUnits attribute of the <filter> element.

Value<number>
Default value2
AnimatableYes

feOffset

For <feOffset>, dx defines the x offset of the filter input graphic. The unit used to resolve the value of the attribute is set by the primitiveUnits attribute of the <filter> element.

Value<number>
Default value0
AnimatableYes

glyphRef

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

For <glyphRef>, dx defines the x offset of the glyph, in the font metric system.

Value<number>
Default value0
AnimatableYes

text

For <text>, if it contains a single value, dx defines a shift along the x-axis for all glyphs.

If there are multiple values, dx defines a shift along the x-axis for each individual glyph relative to the preceding glyph. If there are less values than glyphs, the remaining glyphs use a value of 0. If there are more values than glyphs, extra values are ignored.

ValueList of <length>
Default valuenone
AnimatableYes

Example

html,body,svg { height:100% }
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Lines materialized the position of the glyphs -->
  <line x1="0"  x2="100%" y1="25%" y2="25%" />
  <line x1="0"  x2="100%" y1="50%" y2="50%" />
  <line x1="0"  x2="100%" y1="75%" y2="75%" />

  <line x1="10%" x2="10%" y1="0"   y2="100%" />
  <line x1="30%" x2="30%" y1="0"   y2="100%" />
  <line x1="60%" x2="60%" y1="0"   y2="100%" />

  <!-- Behaviors change based on the number
       of values in the attributes -->
  <text dx="20%"       x="10%" y="25%">SVG</text>
  <text dx="0 10%"     x="10%" y="50%">SVG</text>
  <text dx="0 10% 20%" x="10%" y="75%">SVG</text>
</svg>
line {
  stroke: red;
  stroke-width: .5px;
  stroke-dasharray: 3px;
}

tref

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

For <tref>, if it contains a single value, dx defines a shift along the x-axis for all glyphs.

If there are multiple values, dx defines a shift along the x-axis for each individual glyph relative to the preceding glyph. If there are less values than glyphes, the remaining glyphes use a value of 0. If there are more values than glyphes, extra values are ignored.

ValueList of <length>
Default valuenone
AnimatableYes

tspan

For <tspan>, if it contains a single value, dx defines a shift along the x-axis for all alternate glyph.

If there are multiple values, dx defines a shift along the x-axis for each individual glyph relative to the preceding glyph. If there are less values than glyphs, the remaining glyphs use a value of 0. If there are more values than glyphs, extra values are ignored.

ValueList of <length>
Default valuenone
AnimatableYes

Specifications

SpecificationStatusComment
Filter Effects Module Level 1
The definition of 'dx' in that specification.
Working DraftInitial definition for <feDropShadow>
Filter Effects Module Level 1
The definition of 'dx' in that specification.
Working DraftDefinition for <feOffset>
Scalable Vector Graphics (SVG) 2
The definition of 'dx' in that specification.
Candidate RecommendationDefinition for <text> and <tspan>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'dx' in that specification.
RecommendationInitial definition for <feOffset>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'dx' in that specification.
RecommendationInitial definition for <altGlyph>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'dx' in that specification.
RecommendationInitial definition for <glyphRef>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'dx' in that specification.
RecommendationInitial definition for <text>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'dx' in that specification.
RecommendationInitial definition for <tref> and <tspan>

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

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

发布评论

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

词条统计

浏览:106 次

字数:13351

最后编辑:6 年前

编辑次数:0 次

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