svg標簽和svg文件區別_什么是SVG文件? SVG圖片和標簽說明

svg標簽和svg文件區別

SVG (SVG)

SVG or Scalable Vector Graphics is a web standard for defining vector-based graphics in web pages. Based on XML the SVG standard provides markup to describe paths, shapes, and text within a viewport. The markup can be embedded directly into HTML for display or saved to a .svg file and inserted like any other image.

SVG或可伸縮矢量圖形是用于在網頁中定義基于矢量的圖形的Web標準。 SVG標準基于XML,提供標記來描述視口內的路徑,形狀和文本。 標記可以直接嵌入HTML中以顯示,也可以保存到.svg文件中,然后像插入其他任何圖像一樣插入。

You can write SVG by hand, but more complicated graphics can be designed in vector graphics editors such as Illustrator or InkScape and exported to SVG files or code.

您可以手工編寫SVG,但是可以在矢量圖形編輯器(例如Illustrator或InkScape)中設計更復雜的圖形,并將其導出到SVG文件或代碼中。

SVG基礎 (SVG Basics)

Developers start an SVG graphic with the <svg> tag and XML namespace like so:

開發人員使用<svg>標記和XML名稱空間啟動SVG圖形,如下所示:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>

The sample also includes a version attribute. The version attribute is optional but it is recommended for complaince with XML specifications.

該示例還包括version屬性。 version屬性是可選的,但建議使用XML規范進行投訴。

This sample won’t display anything, it merely established a viewport. You can add height and width attributes to set a display size for the viewport this essentially establishes a canvas for you to work in.

該示例將不顯示任何內容,僅建立了一個視口。 您可以添加heightwidth屬性來設置視口的顯示大小,這實際上為您創建了一個畫布供您使用。

With a viewport in place you can add basic graphics, text, and path elements.

在適當的視口下,您可以添加基本的圖形,文本和路徑元素。

<svgversion="1.1"width="100%"viewbox="0 0 600 300"xmlns="http://www.w3.org/2000/svg"><rect x="10" y="10" width="100" height="100" fill="#f7b2c1" /><circle cx="240" cy="60" r="50" fill="#c1b2f7" stroke="#b2c1f7" stroke-width="15"/><text x="450" y="70" font-size="20" text-anchor="middle">SVG Text is browser readable!</text><g stroke="#b2c1f7"> <!-- g is for group --><path stroke-width="2" d="M10 170 l590 0" /><path stroke-width="4" d="M10 190 l590 0" /><path stroke-width="6" d="M10 210 l590 0" /></g>  
</svg>

You can see the output and play with the code in this codepen.

您可以看到輸出并使用此Codepen中的代碼。

In the opening svg tag we add a width attribute to set the width of the viewport to 100% of the container width, you can use percentages or pixel widths. The opening svg tag also has viewbox attribute which defines a window through which elements of your svg are visible, in this case, the viewbox spans from (0,0) to (600,300). In SVG space the X-axis starts with zero on the left and increases to the right; the Y-axis starts with zero at the top and increases towards the bottom.

在開頭的svg標簽中,我們添加了width屬性,以將視口的寬度設置為容器寬度的100%,您可以使用百分比或像素寬度。 開頭的svg標記還具有viewbox屬性,該屬性定義了一個窗口,通過該窗口可以看到svg的元素,在這種情況下,viewbox的范圍為(0,0)到(600,300)。 在SVG空間中,X軸從左側的零開始,向右增加; Y軸從頂部的零開始,向底部增加。

The first new tag is the <rect /> tag which defines a rectangle in the SVG viewport. In this case we define a square which is 10 units from the top and left and 100 units tall and wide. The fill attribute sets the fill color for the shape.

第一個新標簽是<rect />標簽,該標簽在SVG視口中定義了一個矩形。 在這種情況下,我們定義了一個正方形,該正方形從頂部和左側開始分別為10個單位,從高和寬為100個單位。 fill屬性設置形狀的填充顏色。

Next we define a circle or oval with the <circle /> tag. The sample defines a circle centered at (240,60) with a radius of 50 units. The stroke and stroke-width attributes set a stroke color and a size for the stroke.

接下來,我們用<circle />標記定義一個圓形或橢圓形。 該示例定義了一個以(240,60)為中心的圓,半徑為50個單位。 strokestroke-width屬性設置筆劃的顏色和大小。

You can add text to the graphic with the text tag. The sample text is anchored from the middle of the text to a point at (450, 70) and has a font size of 20 units. The nice thing about text in SVG is it will scale with the rest of your graphic, but it is still readable by the browser and web bots.

您可以使用text標簽將文本添加到圖形中。 示例文本從文本的中間錨定到(450,70)處的一點,并且字體大小為20個單位。 SVG中文本的好處是它可以隨圖形的其余部分縮放,但仍可被瀏覽器和Web bot讀取。

When you want to apply the same attributes or CSS styles to multiple SVG elements you can group them with the <g> tag. Attributes assigned to the <g> tag, like the stroke attribute in the example, will be applied to all elements within the group. In this case three <path /> elements.

當您要將相同的屬性或CSS樣式應用于多個SVG元素時,可以使用<g>標簽將它們分組。 分配給<g>標記的屬性(如示例中的stroke屬性)將應用于組中的所有元素。 在這種情況下,三個<path />元素。

The <path /> element defines a vector path in the viewport. The path is defined by the d attribute. In the first example the definition reads ‘move to the absolute coordinate (10, 170) and draw a line to the relative coordinates 590 in the X direction and 0 in the Y direction.

<path />元素在視口中定義矢量路徑。 路徑由d屬性定義。 在第一個示例中,定義讀取為“移動到絕對坐標(10,170), 在X方向上畫一條線到相對坐標590,在Y方向上畫一條線到0。

The following commands can be used to create your path:

以下命令可用于創建路徑:

M = move to L = line to H = horizontal line to V = vertical line to Z = close path C = (cubic bezier) curve to S = smooth curve to Q = quadratic bezier curve to T = smooth quadratic bezier curve to A = arc

M =移動到L =直線到H =水平線到V =垂直線到Z =閉合路徑C =(三次貝塞爾曲線)到S =平滑曲線到Q =二次貝塞爾曲線到T =二次貝塞爾曲線平滑到A =弧

畫布元素 (The canvas element)

Canvas graphics can be drawn onto a

畫布圖形可以繪制到

A context is created through the getContext method on the

上下文是通過getContext方法在

<p > Before canvas . </p >
< canvas width ="120" height ="60" > </ canvas >
<p > After canvas . </p >
< script >
var canvas = document . querySelector (" canvas ") ;
var context = canvas . getContext ("2 d ") ;
context . fillStyle = " red ";
context . fillRect (10 , 10 , 100 , 50) ;
</ script >

After creating the context object, the example draws a red rectangle 100 pixels wide and 50 pixels high, with its top-left corner at coordinates (10,10).

創建上下文對象后,該示例繪制一個100像素寬,50像素高的紅色矩形,其左上角位于坐標(10,10)處。

繪制餅圖 (Drawing a pie chart)

The results variable contains an array of objects that represent the survey responses.

結果變量包含代表調查響應的對象數組。

var results = [
{ name : " Satisfied " , count : 1043 , color : " lightblue "} ,
{ name : " Neutral " , count : 563 , color : " lightgreen "} ,
{ name : " Unsatisfied " , count : 510 , color : " pink "} ,
{ name : " No comment " , count : 175 , color : " silver "}
];

To draw a pie chart, we draw a number of pie slices, each made up of an arc and a pair of lines to the center of that arc. We can compute the angle taken up by each arc by dividing a full circle (2 π ) by the total number of responses and then multiplying that number (the angle per response) by the number of people who picked a given choice.

要繪制餅圖,我們繪制了許多餅圖,每個餅圖由一個圓弧和指向該圓弧中心的一對線組成。 我們可以通過將一個完整的圓(2π)除以響應總數,然后將該數字(每個響應的角度)乘以選擇給定選擇的人數來計算每個弧所占的角度。

< canvas width ="200" height ="200" > </ canvas >
< script >
var cx = document . querySelector (" canvas ") . getContext ("2 d ") ;
var total = results . reduce ( function ( sum , choice ) {
return sum + choice . count ;
} , 0) ;// Start at the topvar currentAngle = -0.5 * Math . PI ;
results . forEach ( function ( result ) {
var sliceAngle = ( result . count / total ) * 2 * Math . PI ;
cx . beginPath () ;
// center =100 ,100 , radius =100
// from current angle , clockwise by slice ' s angle
cx . arc (100 , 100 , 100 ,
currentAngle , currentAngle + sliceAngle );
currentAngle += sliceAngle ;
cx . lineTo (100 , 100) ;
cx . fillStyle = result . color ;
cx . fill () ;
}) ;
</ script >

This draws the following chart:

得出以下圖表:

瀏覽器支持 (Browser Support)

Browser support for SVG is available in all modern browsers. There are some issues with scaling in IE 9 through IE 11 however they can be overcome with the use of the width, height, viewbox, and CSS.

所有現代瀏覽器均提供對SVG的瀏覽器支持 。 在IE 9到IE 11中,縮放存在一些問題,但是可以通過使用widthheightviewbox和CSS來解決。

編者 (Editors)

  • Vectr - web and desktop tool fot creating and editing SVG graphics, free of charge

    Vectr-免費創建和編輯SVG圖形的Web和桌面工具

創建SVG的工具 (Tools to create SVG)

There are few tools available to create SVG in the form of drawing program.

幾乎沒有可用的工具以繪圖程序的形式創建SVG。

  • Inkscape - It is an open source tool for state-of-the-art vector drawing with an easy to use graphical interface.

    Inkscape-這是一個用于使用最新技術繪制圖形的開源工具,具有易于使用的圖形界面。

  • Adobe Illustrator - Adobe Illustrator is a commercial tool for Vector Imagery.

    Adobe Illustrator -Adobe Illustrator是用于Vector Imagery的商業工具。

For more tools, refer to W3C list of tools that supports SVG

有關更多工具,請參閱支持SVG的W3C工具列表。

為什么要使用SVG (Why you should use SVGs)

As a vector image format, it allows you to resize an image without any loss of quality and a particularly light weight. As an XML format, it allows you to benefit from the full power of JavaScript and especially CSS.

作為矢量圖像格式,它使您可以調整圖像大小,而不會損失質量和特別輕的重量。 作為XML格式,它使您可以從JavaScript尤其是CSS的全部功能中受益。

有關SVG的更多信息: (More info on SVGs:)

  • Why you should use SVG images

    為什么要使用SVG圖像

  • What you need to know to work with SVG in VS Code

    在VS Code中使用SVG需要了解的知識

  • How to make your fancy SVG button accessible

    如何使您喜歡的SVG按鈕可訪問

翻譯自: https://www.freecodecamp.org/news/svg-basics-what-are-scalable-vector-graphics-and-how-do-you-use-them/

svg標簽和svg文件區別

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390763.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390763.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390763.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

開發人員怎么看實施人員

英文原文&#xff1a;What Developers Think Of Operations&#xff0c;翻譯&#xff1a;張紅月CSDN 在一個公司里面&#xff0c;開發和產品實施對于IS/IT的使用是至關重要的&#xff0c;一個負責產品的研發工作&#xff0c;另外一個負責產品的安裝、調試等工作。但是在開發人員…

怎么評價兩組數據是否接近_接近組數據(組間)

怎么評價兩組數據是否接近接近組數據(組間) (Approaching group data (between-group)) A typical situation regarding solving an experimental question using a data-driven approach involves several groups that differ in (hopefully) one, sometimes more variables.使…

代碼審計之DocCms漏洞分析

0x01 前言 DocCms[音譯&#xff1a;稻殼Cms] &#xff0c;定位于為企業、站長、開發者、網絡公司、VI策劃設計公司、SEO推廣營銷公司、網站初學者等用戶 量身打造的一款全新企業建站、內容管理系統&#xff0c;服務于企業品牌信息化建設&#xff0c;也適應用個人、門戶網站建設…

你讓,勛爵? 使用Jenkins聲明性管道的Docker中的Docker

Resources. When they are unlimited they are not important. But when theyre limited, boy do you have challenges! 資源。 當它們不受限制時&#xff0c;它們并不重要。 但是&#xff0c;當他們受到限制時&#xff0c;男孩你有挑戰&#xff01; Recently, my team has fa…

翻譯(九)——Clustered Indexes: Stairway to SQL Server Indexes Level 3

原文鏈接&#xff1a;www.sqlservercentral.com/articles/StairwaySeries/72351/ Clustered Indexes: Stairway to SQL Server Indexes Level 3 By David Durant, 2013/01/25 (first published: 2011/06/22) The Series 本文是階梯系列的一部分&#xff1a;SQL Server索引的階梯…

power bi 中計算_Power BI中的期間比較

power bi 中計算Just recently, I’ve come across a question on the LinkedIn platform, if it’s possible to create the following visualization in Power BI:就在最近&#xff0c;我是否在LinkedIn平臺上遇到了一個問題&#xff0c;是否有可能在Power BI中創建以下可視化…

-Hive-

Hive定義 Hive 是一種數據倉庫技術&#xff0c;用于查詢和管理存儲在分布式環境下的大數據集。構建于Hadoop的HDFS和MapReduce上&#xff0c;用于管理和查詢分析結構化/非結構化數據的數據倉庫; 使用HQL&#xff08;類SQL語句&#xff09;作為查詢接口&#xff1b;使用HDFS作…

CentOS 7 安裝 JDK

2019獨角獸企業重金招聘Python工程師標準>>> 1、下載oracle jdk 下載地址&#xff1a; http://www.oracle.com/technetwork/java/javase/downloads/index.html 選擇同一協議&#xff0c;下載rpm格式版本jdk&#xff0c;或tar.gz格式jdk。 2、卸載本機openjdk 2.1、查…

javascript 布爾_JavaScript布爾說明-如何在JavaScript中使用布爾

javascript 布爾布爾型 (Boolean) Booleans are a primitive datatype commonly used in computer programming languages. By definition, a boolean has two possible values: true or false.布爾值是計算機編程語言中常用的原始數據類型。 根據定義&#xff0c;布爾值有兩個…

如何進行數據分析統計_對您不了解的數據集進行統計分析

如何進行數據分析統計Recently, I took the opportunity to work on a competition held by Wells Fargo (Mindsumo). The dataset provided was just a bunch of numbers in various columns with no indication of what the data might be. I always thought that the analys…

經典:區間dp-合并石子

題目鏈接 &#xff1a;http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid737 這個動態規劃的思是&#xff0c;要得出合并n堆石子的最優答案可以從小到大枚舉所有石子合并的最優情況&#xff0c;例如要合并5堆石子就可以從&#xff0c;最優的23和14中得到最佳的答案。從兩堆…

常見排序算法_解釋的算法-它們是什么以及常見的排序算法

常見排序算法In its most basic form, an algorithm is a set of detailed step-by-step instructions to complete a task. For example, an algorithm to make coffee in a french press would be:在最基本的形式中&#xff0c;算法是一組完成任務的詳細分步說明。 例如&…

020-Spring Boot 監控和度量

一、概述 通過配置使用actuator查看監控和度量信息 二、使用 2.1、建立web項目&#xff0c;增加pom <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency> 啟動項目&a…

matplotlib布局_Matplotlib多列,行跨度布局

matplotlib布局For Visualization in Python, Matplotlib library has been the workhorse for quite some time now. It has held its own even after more nimble rivals with easier code interface and capabilities like seaborn, plotly, bokeh etc. have arrived on the…

Hadoop生態系統

大數據架構-Lambda Lambda架構由Storm的作者Nathan Marz提出。旨在設計出一個能滿足實時大數據系統關鍵特性的架構&#xff0c;具有高容錯、低延時和可擴展等特性。Lambda架構整合離線計算和實時計算&#xff0c;融合不可變性&#xff08;Immutability&#xff09;&#xff0c…

javascript之 原生document.querySelector和querySelectorAll方法

querySelector和querySelectorAll是W3C提供的 新的查詢接口&#xff0c;其主要特點如下&#xff1a; 1、querySelector只返回匹配的第一個元素&#xff0c;如果沒有匹配項&#xff0c;返回null。 2、querySelectorAll返回匹配的元素集合&#xff0c;如果沒有匹配項&#xff0c;…

RDBMS數據定時采集到HDFS

[toc] RDBMS數據定時采集到HDFS 前言 其實并不難&#xff0c;就是使用sqoop定時從MySQL中導入到HDFS中&#xff0c;主要是sqoop命令的使用和Linux腳本的操作這些知識。 場景 在我們的場景中&#xff0c;需要每天將數據庫中新增的用戶數據采集到HDFS中&#xff0c;數據庫中有tim…

單詞嵌入_神秘的文本分類:單詞嵌入簡介

單詞嵌入Natural language processing (NLP) is an old science that started in the 1950s. The Georgetown IBM experiment in 1954 was a big step towards a fully automated text translation. More than 60 Russian sentences were translated into English using simple…

使用Hadoop所需要的一些Linux基礎

Linux 概念 Linux 是一個類Unix操作系統&#xff0c;是 Unix 的一種&#xff0c;它 控制整個系統基本服務的核心程序 (kernel) 是由 Linus 帶頭開發出來的&#xff0c;「Linux」這個名稱便是以 「Linus’s unix」來命名的。 Linux泛指一類操作系統&#xff0c;具體的版本有&a…

python多項式回歸_Python從頭開始的多項式回歸

python多項式回歸Polynomial regression in an improved version of linear regression. If you know linear regression, it will be simple for you. If not, I will explain the formulas here in this article. There are other advanced and more efficient machine learn…