dy

dy 属性指示元素或其内容的位置沿 y 轴的偏移量。

你可以将此属性与以下 SVG 元素一起使用

示例

html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Lines materialized the position of the glyphs -->
  <line x1="10%" x2="10%" y1="0" y2="100%" />
  <line x1="0" x2="100%" y1="30%" y2="30%" />
  <line x1="0" x2="100%" y1="80%" y2="80%" />

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

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

feDropShadow

对于 <feDropShadow>dy 定义了投射阴影的 y 轴偏移量。用于解析该属性值的单位由 <filter> 元素的 primitiveUnits 属性设置。

<number>
默认值 2
可动画的

feOffset

对于 <feOffset>dy 定义了滤镜输入图形的 y 轴偏移量。用于解析该属性值的单位由 <filter> 元素的 primitiveUnits 属性设置。

<number>
默认值 0
可动画的

文本

对于 <text>,如果它包含单个值,dy 定义了所有字形的 y 轴偏移量。

如果有多个值,dy 定义了每个字形相对于前一个字形在 y 轴上的偏移量。如果值少于字形数量,则其余字形使用 0 值。如果值多于字形数量,则忽略多余的值。

列表(<length> | <percentage>
默认值 none
可动画的

示例

html
<svg viewBox="0 0 150 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Horizontal lines -->
  <line x1="0" x2="100%" y1="30" y2="30" />
  <line x1="0" x2="100%" y1="40" y2="40" />
  <line x1="0" x2="100%" y1="50" y2="50" />
  <line x1="0" x2="100%" y1="60" y2="60" />

  <!-- Vertical lines -->
  <line x1="10" x2="10" y1="0" y2="100%" />
  <line x1="50" x2="50" y1="0" y2="100%" />
  <line x1="90" x2="90" y1="0" y2="100%" />

  <!-- Behaviors change based on the number of values in the attributes -->
  <text dy="20" x="10" y="30">SVG</text>
  <text dy="0 10" x="50" y="30">SVG</text>
  <text dy="0 10 20" x="90" y="30">SVG</text>
</svg>
css
line {
  stroke: red;
  stroke-width: 0.5px;
  stroke-dasharray: 3px;
}

tspan

对于 <tspan>,如果它包含单个值,dy 定义了所有备用字形在 y 轴上的偏移量。

如果有多个值,dy 定义了每个字形相对于前一个字形在 y 轴上的偏移量。如果值少于字形数量,则其余字形使用 0 值。如果值多于字形数量,则忽略多余的值。

列表(<length> | <percentage>
默认值 none
可动画的

规范

规范
滤镜效果模块第 1 级
# element-attrdef-fedropshadow-dy
滤镜效果模块第 1 级
# element-attrdef-feoffset-dy
Scalable Vector Graphics (SVG) 2
# TextElementDYAttribute