当前位置:网站首页>svg中viewbox图解分析
svg中viewbox图解分析
2022-06-12 08:28:00 【月来better】

svg中有一个viewbox属性,中文翻译为视区,就是在svg上截取一小块,放大到整个svg显示。
这个属性初学的话有点难以理解,这边做一个简单的示例,一看就明白了。
1)先来一个svg,宽高各位300,设置一下边框:
<svg width="300" height="300" style="border: 1px solid steelblue">
</svg>
运行效果:

这边其实就是一个300*300的矩形。
2)svg里面画一个矩形:
<svg width="300" height="300" style="border: 1px solid steelblue">
<rect x="10" y="10" width="200" height="100" fill="skyblue"></rect>
</svg>
运行效果:
3)设置svg的viewbox属性:
<svg width="300" height="300" style="border: 1px solid steelblue"
viewbox="105 55 60 60">
<rect x="10" y="10" width="200" height="100" fill="skyblue"></rect>
</svg>
先分析一下原理,再来看效果,上面设置的viewbox的值为:105 55 60 60,每个参数的含义如下:
105 表示相对于svg左上角的横坐标。
55 表示相对于svg左上角的纵坐标。
60 表示截取的视区的宽度。
60 表示截取的视区的高度。
图示原理:

4) 非等比例的viewbox
上面的viewbox宽高和svg等比例,如果等比例,那么就是其中一边放到最大。
<svg width="300" height="300" style="border: 1px solid steelblue"
viewbox="105 55 60 60">
<rect x="10" y="10" width="200" height="100" fill="skyblue"></rect>
</svg>
图示原理:
边栏推荐
猜你喜欢

Centos8 installing MySQL 8.0 (upper)

【 pointeur avancé Ⅲ】 mise en œuvre de la fonction de tri rapide qsort& fonction de rappel en langage C

What exactly is APS? You will know after reading the article

智能制造的时代,企业如何进行数字化转型

Hands on deep learning -- discarding method and its code implementation

Hypergeometric cumulative distribution test overlap

制造企业生产排产现状和APS系统的解决方案

(P17-P18)通过using定义基础类型和函数指针别名,使用using和typedef给模板定义别名

(p36-p39) right value and right value reference, role and use of right value reference, derivation of undetermined reference type, and transfer of right value reference

【进阶指针一】字符数组&数组指针&指针数组
随机推荐
Ankerui fire emergency lighting and evacuation indication system
Hands on learning and deep learning -- simple implementation of softmax regression
Configuration and principle of MSTP
Vscode 调试TS
MES系统质量追溯功能,到底在追什么?
Hands on deep learning -- image classification dataset fashion MNIST
如何理解APS系统的生产排程?
Vscade debug TS
余压监控系统保证火灾发生时消防疏散通道的通畅,为大型高层建筑的安全运行和人民生命财产安全保驾护航
Instructions spéciales pour l'utilisation du mode nat dans les machines virtuelles VM
Figure neural network makes Google maps more intelligent
Install iptables services and open ports
Error: what if the folder cannot be deleted when it is opened in another program
Project sorting of niuke.com
FPGA implementation of right and left flipping of 720p image
MYSQL中的锁的机制
目前MES应用很多,为什么APS排程系统很少,原因何在?
MATLAB image processing - cosine noise removal in image (with code)
【动态内存管理】malloc&calloc和realloc和笔试题和柔性数组
The electrical fire detector monitors each power circuit in real time