svg的 viewBox理解

<svg id="ps4" width="400" height="400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 894.7 448.4" style="display: block;" xml:space="preserve">
    <g>
      <path d="M563.9,361.4L582 303.3 892.9 103.1 876.4 156.5 z" style="stroke-dasharray: 861px, 861px; stroke-dashoffset: 0px;"></path>
      <path d="M892.9,103.1L573.4 40.3 571.8 42.7 568.1 41.7 569.7 38.7 388.1 1 41.8 162.8 235.7 212.2 582 303.3 "></path>
      <path d="M225.8,271.4L241.7 213.8 573.4 40.3 " style="stroke-dasharray: 435px, 435px; stroke-dashoffset: 0px;"></path>
      <path d="M221.1,269.8L237.7 212.8 569.7 38.7 " style="stroke-dasharray: 435px, 435px; stroke-dashoffset: 0px;"></path>
      <path d="M41.8,162.8L23.7 217.5 563.9 361.4 " style="stroke-dasharray: 617px, 617px; stroke-dashoffset: 0px;"></path>
      <path d="M51.4,224.8L51.4 235.8 313.6 306.9 " style="stroke-dasharray: 283px, 283px; stroke-dashoffset: 0px;"></path>
      <path d="M848.9,175.1L869.1 178.7 855 232.3 537.8 447.3 407.9 410.3 222.6 357.6 201.2 351.5 202.8 346.4 196 351.5 1.2 297 16.9 242.6 48.9 224.8 " style="stroke-dasharray: 1119px, 1119px; stroke-dashoffset: 0px;"></path>
      <path d="M16.9,242.6L555 388.6 869.1 178.7 " style="stroke-dasharray: 936px, 936px; stroke-dashoffset: 0px;"></path>
      <path d="M547,356.9L547 369.8 395.4 330.7 " style="stroke-dasharray: 170px, 170px; stroke-dashoffset: 0px;"></path>
      <line x1="196" y1="351.5" x2="211.8" y2="295.5"></line>
      <line x1="201.2" y1="351.5" x2="218.1" y2="297.4"></line>
      <g class="usb-ports">
        <path d="M323.9,300.4L323.9 311.2 345.5 316.7 345.5 305.7 z" style="stroke-dasharray: 67px, 67px; stroke-dashoffset: 0px;"></path>
        <line x1="326" y1="308.6" x2="343.3" y2="312.5"></line>
        <path d="M370.2,313.1L370.2 323.8 391.8 329.3 391.8 318.3 z" style="stroke-dasharray: 67px, 67px; stroke-dashoffset: 0px;"></path>
        <line x1="372.3" y1="321.2" x2="389.6" y2="325.1"></line>
      </g>
      <g class="ps4-logo">
        <path d="M475.6,313.8l2.7-6.7l13.5,4.1c1.9,0.1,7.6-2.1,3-7.1l-14.5-4.1" style="stroke-dasharray: 47px, 47px; stroke-dashoffset: 0px;"></path>
        <path d="M521.4,311.2l-8.4-3c0,0-2.1-0.8-3.1,1.5l-3.7,9.9c0,0-1,1.8-3.1,1.2l-7.7-2.5" style="stroke-dasharray: 35px, 35px; stroke-dashoffset: 0px;"></path>
        <path d="M533.2,330.7L538.9 315.8 519.2 322.2 538.1 328.8 " style="stroke-dasharray: 57px, 57px; stroke-dashoffset: 0px;"></path>
      </g>
    </g>
  </svg>

上述代码中,默认图形大小是894.7 448.4尺寸, 如果不用viewBox 那么在SVG中显示的图形只有完整图形的一部分,也就是400,400部分, 而用了viewBox则会将整个图形截取,然后等比例放大或者缩小,布满svg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: SVGviewBox属性用于定义SVG元素的可见区域和坐标系。它是一个矩形框,由四个值组成,分别表示x、y、width和height。\[1\]在引用\[1\]中的例子中,viewBox的值是"0 0 200 200",表示可见区域的左上角坐标为(0, 0),宽度为200,高度为200。而在引用\[2\]中的例子中,viewBox的值是"105 55 60 60",表示可见区域的左上角坐标为(105, 55),宽度为60,高度为60。\[2\]在使用viewBox属性时,需要设置四个值,分别表示可见区域的左上角坐标和宽度、高度。例如,<svg width="200" height="200" viewbox="0 0 100 100"></svg>中的viewBox属性值是"0 0 100 100",表示可见区域的左上角坐标为(0, 0),宽度为100,高度为100。\[3\] #### 引用[.reference_title] - *1* *3* [svgViewBox详解,秒懂SVG里的viewbox](https://blog.csdn.net/zp19860529/article/details/114173594)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [svgviewbox图解分析](https://blog.csdn.net/Kiruthika/article/details/124974340)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值