在接下来的文章中,我们将学习如何在html5中绘制svg标志。在我们开始阅读文章之前,让我们先讨论一些关于svg的事情。可缩放矢量图形(svg)是一种使用矢量数据的图像格式。与其他格式不同,svg不使用独特的像素来构建图像,而是使用矢量数据。
使用它最好的一点是,使用svg可以制作适应任何分辨率的图片,这使得它们在网页设计和其他许多应用中非常理想。
让我们来看一个简单的例子,以便更好地理解svg
example 的中文翻译为:示例<!doctype html><html><body> <svg width=110 height=150> <circle cx=50 cy=50 r=40 stroke=red stroke-width=4 fill=green /> </svg></body></html>
当脚本被执行时,它将生成一个输出,其中包含在上述脚本中使用给定的尺寸在网页上绘制的一个svg圆。
什么是svg使用svg(一种标记语言)来描述二维矢量图形。这是一种基于文本的技术,可以与css、dom、javascript和smil等其他技术一起使用,以描述任意大小的图像。
svg格式的矢量图片,例如,可以在不失去质量的情况下进行缩放。与像jpeg和png这样的位图图片不同,它们也可以在不需要图形编辑器的情况下进行本地化。
以下是在html5中绘制svg标志的示例example 1的中文翻译为:示例 1在下面的例子中,我们正在网页上创建一个svg标志。
<!doctype html><html><body> <svg height=130 width=500> <defs> <lineargradient id=tutorial x1=10% y1=5% x2=90% y2=10%> <stop offset=0 style=stop-color:rgb(187, 143, 206); /> <stop offset=1 style=stop-color:rgb(192, 57, 43); /> </lineargradient> </defs> <ellipse cx=100 cy=70 rx=85 ry=55 fill=url(#tutorial) /> <text fill=#58d68d font-size=14 font-family=verdana x=50 y=86>tutorialspoint</text> </svg></body></html>
when the script gets executed, it will generate an output consisting of an ellipse drawn with a linear gradient with the text tutorialspoint, which acts as a logo on the webpage.
example 2 的中文翻译为:示例2考虑以下示例,我们正在网页上创建svg徽标
<!doctype html><html><body> <svg width=140px height=320px> <rect x=19 y=19 width=110 height=300 fill=white stroke=black stroke-width=3 /> <circle cx=75 cy=85 r=30 fill=red stroke=black stroke-width=2 /> <circle cx=75 cy=165 r=30 fill=yellow stroke=black stroke-width=2 /> <circle cx=75 cy=245 r=30 fill=#40cc40 stroke=black stroke-width=2 /> </svg> <p>follow traffic signals</p></body></html>
当上述脚本运行时,它将产生一个输出,其中包含使用上述脚本中给定的测量值在网页上绘制的交通信号灯,它充当一个标志。
example 3让我们来看另一个例子,在网页上创建一个svg标志。
<!doctype html><html><head> <title>html5 svg logo</title></head><body> <svg height=170 width=400> <defs> <lineargradient id=lgrad x1=0% y1=0% x2=100% y2=0%> <stop offset=0% style=stop-color:rgb(184,78,43);stop-opacity:1 /> <stop offset=50% style=stop-color:rgb(241,241,241);stop-opacity:1 /> <stop offset=100% style=stop-color:rgb(255,141,52);stop-opacity:1 /> </lineargradient> </defs> <ellipse cx=100 cy=70 rx=85 ry=55 fill=url(#lgrad) /> <text fill=#rgb(141,218,255) font-size=40 font-family=verdana x=50 y=86>logo</text> </svg></body></html>
运行上述脚本后,输出窗口将弹出,显示在网页上使用上述脚本中提到的测量值绘制的带有线性渐变的svg徽标。
以上就是如何在html5中绘制svg标志?的详细内容。