SVG系列一

简介: Note: Since SVG is written in XML, all elements must be properly closed!My first SVG ...

Note: Since SVG is written in XML, all elements must be properly closed!


<!DOCTYPE html>
<html>
<body>

<h1>My first SVG</h1>

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40" stroke="#000" stroke-width="4" fill="#ccc" />
</svg>

</body>
</html>


  • The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, the circle's center is set to (0, 0)
  • The stroke and stroke-width attributes control how the outline of a shape appears. We set the outline of the circle to a 4px green "border"
当然画圆、矩形以及带圆角的矩形大可不必用SVG,普通的CSS就可以搞定。
但如果是画一个椭圆呢?其实如果用CSS设置它的水平半径和垂直半径就行了border-radius: 50px / 100px;
但有了SVG就可以很简单的画出椭圆以及更复杂的矢量图形了。
<svg width="400" height="200">
    <ellipse cx="200" cy="100" rx="180" ry="80" style="fill: #ccc; stroke: #000; stroke-width: 4" />
  </svg>


叠层的椭圆
<svg width="400" height="200">
    <ellipse cx="190" cy="100" rx="180" ry="30" style="fill: red" />
    <ellipse cx="180" cy="70" rx="160" ry="20" style="fill: green" />
    <ellipse cx="170" cy="45" rx="140" ry="15" style="fill: blue" />
  </svg>


目录
相关文章
|
1月前
|
XML 移动开发 前端开发
Canvas和SVG:你应该选择哪一个?
Canvas和SVG:你应该选择哪一个?
29 2
|
2月前
|
Web App开发 移动开发 前端开发
SVG
这段代码将引用刚才定义的圆形,并将其放置在(20,20)的位置,大小为60x60。 除了<svg>和<use>元素外,SVG还提供了许多其他的元素和属性,可以帮助你创建各种复杂的图形。比如<rect>、<line>、<polygon>等元素,可以用来创建矩形、线条和多边形等。
23 0
|
3月前
|
前端开发 JavaScript API
【HTML】SVG实现炫酷的描边动画
今天闲来无事,看到Antfu大佬的个性签名,觉得还是非常炫酷的,于是也想要搞一个自己的个性签名用来装饰自己的门面,不过由于手写的签名太丑了,遂放弃。于是尝试理解原理,深入研究此等密法,终于小有所成,发现原来是描边动画,于是记载如下,方便日后借鉴。
49 3
|
5月前
|
XML 移动开发 前端开发
canvas与svg区别与实际应用
canvas与svg区别与实际应用
32 0
|
6月前
|
XML 编解码 前端开发
canvas和svg的区别?
canvas和svg的区别?
|
6月前
|
前端开发
canvas 和 svg 的区别是什么?
canvas 和 svg 的区别是什么?
17 0
|
8月前
用svg实现一个环形进度条
用svg实现一个环形进度条
43 0
|
前端开发
你可以学会的svg动画
你可以学会的svg动画
|
XML 前端开发 JavaScript
你可以学会的svg动画(SMIL)
你可以学会的svg动画(SMIL)
|
XML 前端开发 JavaScript
Day26 - Canvas 与 SVG的区别
Day26 - Canvas 与 SVG的区别
104 0