将SVG图像编码为URL安全格式,用于CSS背景图像、边框图像或蒙版
不进行编码的话,我们可以以data URI形式在CSS中直接使用SVG,但这仅在基于Webkit的浏览器中有效;如果用encodeURIComponent()对SVG编码,就可在全部地方都生效。
data URI
encodeURIComponent()
SVG必须有xmlns属性,例如:xmlns='http://www.w3.org/2000/svg'。如果不存在则会自动添加。
xmlns='http://www.w3.org/2000/svg'
编码后的SVG可在background、border-image或mask中使用。
background
border-image
mask