大网数据广告活动
Web 标准与前端开发

dy

· 52CE 我爱测

The **`dy`** attribute indicates a shift along the y-axis on the position of an element or its content.

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

You can use this attribute with the following SVG elements:

  • feDropShadow
  • feOffset
  • text
  • tspan

feDropShadow

For feDropShadow, dy defines the y offset of the dropped shadow. The unit used to resolve the value of the attribute is set by the primitiveUnits attribute of the filter element.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><code>2</code></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

feOffset

For feOffset, dy defines the y 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.

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#number"><number></a></strong > </td> </tr> <tr> <th scope="row">Default value</th> <td><code>0</code></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

text

For text, if it contains a single value, dy defines a shift along the y-axis for all glyphs.

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

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> List of (<strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#length" ><length></a ></strong > | <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#percentage" ><percentage></a ></strong >) </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

tspan

For tspan, if it contains a single value, dy defines a shift along the y-axis for all alternate glyph.

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

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td> List of (<strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#length" ><length></a ></strong > | <strong ><a href="/en-US/docs/Web/SVG/Guides/Content_type#percentage" ><percentage></a ></strong >) </td> </tr> <tr> <th scope="row">Default value</th> <td><em>none</em></td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

Examples

Shifting text

html,
body,
svg {
  height: 100%;
}
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  
  <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%" />

  
  <text x="10%" y="30%" fill="grey">SVG</text>

  
  <text dy="50%" x="10%" y="30%">SVG</text>
</svg>
line {
  stroke: red;
  stroke-width: 0.5px;
  stroke-dasharray: 3px;
}

Shifting text

Multiple values

html,
body,
svg {
  height: 100%;
}
<svg viewBox="0 0 150 100" xmlns="http://www.w3.org/2000/svg">
  
  <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" />

  
  <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%" />

  
  <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>
line {
  stroke: red;
  stroke-width: 0.5px;
  stroke-dasharray: 3px;
}

Multiple values

Specifications

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。