<defs>
<defs> SVG 元素用于存储稍后将使用的图形对象。在 <defs> 元素内部创建的对象不会直接渲染。要显示它们,您必须引用它们(例如,使用 <use> 元素)。
图形对象可以从任何地方引用,但是,将这些对象定义在 <defs> 元素内部可以提高 SVG 内容的可理解性,并有利于文档的整体可访问性。
使用语境
属性
此元素仅包含全局属性。
DOM 接口
此元素实现了 SVGDefsElement 接口。
示例
html
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
<!-- Some graphical objects to use -->
<defs>
<circle id="myCircle" cx="0" cy="0" r="5" />
<linearGradient id="myGradient" gradientTransform="rotate(90)">
<stop offset="20%" stop-color="gold" />
<stop offset="90%" stop-color="red" />
</linearGradient>
</defs>
<!-- using my graphical objects -->
<use x="5" y="5" href="#myCircle" fill="url('#myGradient')" />
</svg>
规范
| 规范 |
|---|
| Scalable Vector Graphics (SVG) 2 # 头部 |
浏览器兼容性
加载中…