当前位置:网站首页>How to use SVG to make text effects arranged along any path
How to use SVG to make text effects arranged along any path
2022-07-19 10:37:00 【InfoQ】
Preface
demotransformcsscssSVGSVGSVGSVG
Basic knowledge of
What is?
SVG
SVGRefers to scalable vector graphics (Scalable Vector Graphics), In the case of enlarging or changing the size, the graphic quality will not be lost .
SVGUseXMLFormat definition drawing , Used to define vector based graphics for networks .
SVGIs the standard of the World Wide Web Alliance , AndDOMandXSLAnd so on.W3CStandards are a whole .
<path> Path elements
<path><path><path>- M: Move the pen to the specified point x,y Instead of drawing .
- a: From current point to point x,y Draw an elliptical arc .
- z: Close the path by drawing a line from the current point to the first point .
viewBox
attribute
viewBox( View box )<svg><svg>ViewBoxSVGwidth:500px; height:500px; viewBox="0 0 50 20" View box (ViewBox)<svg>SVGSVGx="10" y="10" width="20" height="20"SVG50px50px100px100px<style>
.box {
width: 200px;
height: 200px;
}
</style>
<div class="box">
<svg viewBox="0 0 100 100">
<path d="M0, 50 a50, 50 0 1, 1 0, 1z"></path>
</svg>
<div>

Use
<textPath>
Let the text follow the path
<textpath><text>SVG<textPath>xlink:href="#xxx"IDxxx<path><textPath><text><style>
body {
background-color: #b0b0b0;
}
.box {
width: 200px;
height: 200px;
margin: 50px;
background-color: #fff;
}
</style>
<div class="box">
<svg viewBox="0 0 100 100">
<path d="M0,50 a50,50 0 1,1 0,1z" id="circle" ></path>
<text>
<textPath xlink:href="#circle"> This is the circular text generated around the path ~</textPath>
</text>
</svg>
<div>

- 1, The circular path is filled with default black .
- 2,
SVGActual width and height inherited from.boxThe box , Width and height200px, The overflow part of the text is hidden .
- 1, We can
<path>Elemental fill Set tofill: none;, such , The background of the circular path is transparent .
- 2, to
SVGSet upoverflow: visible;, such , beyondSVGPart of the text will not be hidden .
css.box svg {
overflow: visible;
}
.box path {
fill: none;
}

Create text effects along any path
<path> <style>
.box {
width: 200px;
height: 200px;
margin: 50px;
font-size: 12px;
letter-spacing: 2px;
}
.box svg {
overflow: visible;
}
.box path {
fill: none;
}
</style>
<div class="box">
<svg viewBox="0 0 100 100">
<path d="m36.04045,45.99612c0.72238,0 18.78177,-17.27891 34.67404,-2.30385c15.89227,14.97505 -2.06122,51.71385 -33.12338,49.40999c-31.06217,-2.30385 -51.39459,-47.6821 -23.94431,-74.17643c27.45028,-26.49433 76.46594,-21.1417 90.427,-2.34993c13.96106,18.79177 9.22214,37.08444 7.59483,52.18238c-1.62731,15.09794 5.01952,28.13002 23.57052,28.88256c18.551,0.75254 68.69884,1.13642 61.38299,-46.48421" fill-opacity="null" id="circle" ></path>
<linearGradient id="myLinearGradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="red"></stop>
<stop offset="15%" stop-color="orange"></stop>
<stop offset="30%" stop-color="yellow"></stop>
<stop offset="45%" stop-color="green"></stop>
<stop offset="60%" stop-color="cyan"></stop>
<stop offset="80%" stop-color="blue"></stop>
<stop offset="100%" stop-color="purple"></stop>
</linearGradient>
<text fill="url(#myLinearGradient)">
<textPath xlink:href="#circle"> How to use SVG Create text effects along any path ~ Let's review with the big ice ~</textPath>
</text>
</svg>
</div>

Postscript
SVG<path> Elements SVG<path> Elements 边栏推荐
- Detailed explanation of C language custom types
- AutoJs学习-动态解密
- YARN环境中应用程序JAR包冲突问题的分析及解决
- 2022年全国最新消防设施操作员(中级消防设施操作员)模拟试题及答案
- 开发第一个Flink应用
- HCIA review and answer 2022.7.6
- Studio 3T无限试用
- Analysis and solution of application jar package conflict in yarn environment
- 如何在双链笔记软件中建立仪表盘和知识库?以嵌入式小组件库 NotionPet 为例
- 破案了卧槽---从MQ消费的逻辑怎么改代码都不生效
猜你喜欢
随机推荐
BEV空间内的特征级融合
旋转矩阵(Rotate Matrix)的性质分析(转发)
Figure an introduction to the interpretable method of neural network and a code example of gnnexplainer interpreting prediction
多元线性回归详解
【PostgreSQL 】PostgreSQL 15对distinct的优化
双向NAT技术
Huawei wireless device configuration intelligent roaming
opencv 画黑色矩形,并写上序号
R语言ggplot2可视化:使用ggpubr包的gghistogram函数可视化分组直方图、使用palette参数自定义分组直方图的条形边框颜色
[Acwing]第 60 场周赛 B- 4495. 数组操作
破案了卧槽---从MQ消费的逻辑怎么改代码都不生效
爱可可AI前沿推介(7.17)
HCIA OSPF
从“被动”到“主动”,ZETA技术助力“RFID2.0”升级该如何实现?
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化点状条带图(dot strip plot)、设置add参数为mean_sd添加均值标准差竖线、设置error.plot
C language structure to realize simple address book
String类型函数传递问题
[Niuke swipe questions] / *c language realizes left-hand rotation of strings*/
C语言之构造类型细讲
Date -- machine test topic for postgraduate entrance examination of Guizhou University









