Home > Article > Web Front-end > Use HTML5 SVG to draw various snowflake patterns
In the previous article, we introduced the method of using HTML5 CSS3 to dynamically draw a smiley face. If you are interested, you can click on the link to read → "How to use HTML5 CSS3 to dynamically draw a smiling face". This time we continue to talk about using HTML5 SVG to draw patterns.
The main content of today’s article is: using HTML5 svg to draw various snowflake patterns.
First of all, let’s understand what svg is?
SVG is the abbreviation of Scalable Vector Graphics. It is a graphics format in which shapes are specified in XML. The XML is then rendered by the SVG viewer. Today, most web browsers can display SVG just like they can display PNG, GIF, and JPG. SVG is used for two-dimensional vector graphics.
SVG images are created using various elements that are applied to the structure, drawing, and layout of vector images. If svg is not the root element, the svg element can be used to nest a separate svg fragment within the current document (for example, an HTML document). This independent fragment has its own viewport and coordinate system.
Let’s take a look at how to draw various snowflake patterns using HTML5 SVG.
First set the background color of the entire page, the size of the svg canvas, the color of the lines,
body { background: #222; margin: 0; height: 100vh; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-around; } svg { width: 25vmin; height: 25vmin; } .stroke { fill: none; stroke: #fff; stroke-width: 1; stroke-linecap: round; stroke-linejoin: round; }
Then start using svg to draw various snowflake patterns
Define the svg tag, create the root element of the SVG image, and nest an independent svg fragment within the current document; then use multiple
The first snowflake pattern
第十八种雪花图案
大家可以直接复制以上代码,在本地进行运行演示。
这里给大家介绍几个关键的标签和属性:
元素
SVG 图像是使用各种元素创建的,这些元素分别应用于矢量图像的结构、绘制与布局。如果svg不是根元素,svg 元素可以用于在当前文档(比如说,一个HTML文档)内嵌套一个独立的svg片段 。 这个独立片段拥有独立的视口和坐标系统。
所有SVG图像的根元素都是
路径
path元素是用来定义形状的通用元素。所有的基本形状都可以用path元素来创建。SVG
所有带有
PHP中文网平台有非常多的视频教学资源,欢迎大家学习《HTML视频教程》!
The above is the detailed content of Use HTML5 SVG to draw various snowflake patterns. For more information, please follow other related articles on the PHP Chinese website!