SVG defs元素用法详解

SVG <defs>元素用于嵌入可在SVG映像内重用的定义。

使用SVG <defs>元素, 你可以将SVG形状组合在一起, 并将其作为单个形状重复使用。

当你通过<use>元素引用<defs>元素中定义的形状时, 将显示该形状。

例子

<!DOCTYPE html>
<html>
   <body>
   
<svg>
  <defs>
    <g id="shape">
        <rect x="40" y="40" width="40" height="40" />
        <circle cx="40" cy="40" r="40" />
    </g>
  </defs>

  <use xlink:href="#shape" x="40" y="40" />
  <use xlink:href="#shape" x="160" y="40" />

</svg>

</body>
</html>

立即测试

解释

  • <g>的id属性定义一个唯一的名称。
  • <use>元素通过其xlink:href属性引用<g>元素。
  • #符号定义属性值。
  • <use>元素用于通过其x和y属性指定在何处显示重复使用的形状。
微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_46674.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?