当前位置:网站首页>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 边栏推荐
- 欧拉角,轴角,四元数与旋转矩阵详解
- R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize dot strip plot, and set the add parameter to mean_ SD add the mean standard deviation vertical line and s
- 华为防火墙认证技术
- NJCTF 2017messager
- 圆桌实录:炉边对话——如何在 Web3 实现创新
- HCIA static basic experiment 7.8
- 高效理解 FreeSql WhereDynamicFilter,深入了解设计初衷[.NET ORM]
- Analysis and solution of application jar package conflict in yarn environment
- CPU负载与CPU使用率之区别
- Autojs learning - multi function treasure chest - medium
猜你喜欢
随机推荐
读已提交级别下 注解事务+分布式锁结合引起的事故--活动购买机会的错乱
Lvi-sam: laser IMU camera tight coupling mapping
C # treeview tree structure recursive processing (enterprise group type hierarchical tree display)
Solutions to notebook keyboard failure
R语言使用epiDisplay包的ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、使用summary汇总统计
[Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
2022 Zhejiang secondary vocational group "Cyberspace Security" code information acquisition and analysis (full version)
STM32F407 NVIC
Quick completion guide of manipulator (XIII): joint space trajectory planning
The R language uses the plot function in the native package (basic import package, graphics) to visualize the scatter plot
B. Accuratelee [double pointer] [substr function]
2022 windows penetration test of "Cyberspace Security" of Hunan secondary vocational group (ultra detailed)
自动化之图形界面库pyautogui
破案了卧槽---从MQ消费的逻辑怎么改代码都不生效
Convert excel table to word table, and keep the formula in Excel table unchanged
Huawei wireless device configuration intelligent roaming
2022 Hunan secondary vocational group "Cyberspace Security" packet analysis infiltration Pacpng parsing (super detailed)
Autojs learning - Dynamic decryption
Domestic flagship mobile phones have a serious price foam, and second-hand phones are more cost-effective than new ones, or buy iPhones
内核态和用户态








