y2 属性用于为需要多个坐标才能绘制的 SVG 元素指定第二个 y 坐标。只需一个坐标的元素则使用 y 属性。
元素
你可以将此属性与以下各节所述的 SVG 元素一起使用。
<line>
对于 line,y2 定义线段终点的 y 坐标。
<table class="properties"> <tbody> <tr> <th scope="row">值</th> <td> <strong ><a href="/zh-CN/docs/Web/SVG/Guides/Content_type#长度" ><length></a ></strong >|<strong ><a href="/zh-CN/docs/Web/SVG/Guides/Content_type#百分数" ><percentage></a ></strong >|<strong ><a href="/zh-CN/docs/Web/SVG/Guides/Content_type#数字" ><number></a ></strong > </td> </tr> <tr> <th scope="row">默认值</th> <td><code>0</code></td> </tr> <tr> <th scope="row">动画性</th> <td>是</td> </tr> </tbody> </table>
html,
body,
svg {
height: 100%;
}
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
<line x1="1" x2="9" y1="5" y2="1" stroke="red" />
<line x1="1" x2="9" y1="5" y2="5" stroke="green" />
<line x1="1" x2="9" y1="5" y2="9" stroke="blue" />
</svg>
line
<linearGradient>
对于 linearGradient,y2 定义用于映射色标值的渐变向量终点的 y 坐标。该属性的具体行为受 gradientUnits 属性影响。
<table class="properties"> <tbody> <tr> <th scope="row">值</th> <td> <strong ><a href="/zh-CN/docs/Web/SVG/Guides/Content_type#长度" ><length></a ></strong > </td> </tr> <tr> <th scope="row">默认值</th> <td><code>0%</code></td> </tr> <tr> <th scope="row">动画性</th> <td>是</td> </tr> </tbody> </table>
html,
body,
svg {
height: 100%;
}
<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg">
<linearGradient y2="0%" id="g0">
<stop offset="5%" stop-color="black" />
<stop offset="50%" stop-color="red" />
<stop offset="95%" stop-color="black" />
</linearGradient>
<rect x="1" y="1" width="8" height="8" fill="url(#g0)" />
<linearGradient y2="100%" id="g1">
<stop offset="5%" stop-color="black" />
<stop offset="50%" stop-color="red" />
<stop offset="95%" stop-color="black" />
</linearGradient>
<rect x="11" y="1" width="8" height="8" fill="url(#g1)" />
</svg>
linearGradient
示例
html,
body,
svg {
height: 100%;
}
<svg viewBox="0 0 25 25" xmlns="http://www.w3.org/2000/svg">
<line x1="2" x2="22" y1="20" y2="0" stroke="red" />
<line x1="2" x2="22" y1="20" y2="10" stroke="green" />
<line x1="2" x2="22" y1="20" y2="20" stroke="blue" />
</svg>
示例
规范
浏览器兼容性
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
