用SVG做background image

用SVG做background image1用utf8格式,需要双引号“”替换为单引号,而且采用urlencode编码,例如#替换为%23,body{background-image:url(“data:image/svg+xml;utf8,<svgxmlns=’http://www.w3.org/2000/svg’xmlns:xlink=’http://www.w3.org/1…

用SVG做background

 

 

1 用utf8格式, 需要 双引号“”替换为单引号,而且采用url encode编码,例如# 替换为 %23,

body { background-image:
url(“data:image/svg+xml;utf8,<svg xmlns=’http://www.w3.org/2000/svg’ xmlns:xlink=’http://www.w3.org/1999/xlink’ width=’1060px’ height=’580px’ viewBox=’0 0 1060 580′ preserveAspectRatio=’xMidYMid meet’ ><rect id=’svgEditorBackground’ x=’0′ y=’0′ width=’1060′ height=’580′ style=’fill: none; stroke: none;’/><rect x=’115′ y=’111′ stroke=’black’ id=’e1_rectangle’ style=’stroke-width: 1px;’ width=’144′ height=’120′ fill=’khaki’/><polyline stroke=’black’ stroke-width=’1′ id=’e2_polyline’ style=’fill: none;’ points=’115 109 187 69 257 109′ /><text fill=’black’ x=’257′ y=’33’ id=’e4_texte’ style=’font-family: Arial; font-size: 20px;’></text><rect x=’179′ y=’19’ stroke=’black’ id=’e5_rectangle’ style=’stroke-width: 1px;’ width=’16’ height=’54’ fill=’khaki’ /></svg>”);
}

 

2 用base64格式, 把<svg>… </svg> 用btoa() 转换为base64编码

 

body {
background-image:
url(“data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTA2MHB4IiBoZWlnaHQ9IjU4MHB4IiB2aWV3Qm94PSIwIDAgIDEwNjAgNTgwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBtZWV0IiA+PHJlY3QgaWQ9InN2Z0VkaXRvckJhY2tncm91bmQiIHg9IjAiIHk9IjAiIHdpZHRoPSIxMDYwIiBoZWlnaHQ9IjU4MCIgc3R5bGU9ImZpbGw6IG5vbmU7IHN0cm9rZTogbm9uZTsiLz48cmVjdCB4PSIxMTUiIHk9IjExMSIgc3Ryb2tlPSJibGFjayIgaWQ9ImUxX3JlY3RhbmdsZSIgc3R5bGU9InN0cm9rZS13aWR0aDogMXB4OyIgd2lkdGg9IjE0NCIgaGVpZ2h0PSIxMjAiIGZpbGw9ImtoYWtpIi8+PHBvbHlsaW5lIHN0cm9rZT0iYmxhY2siIHN0cm9rZS13aWR0aD0iMSIgaWQ9ImUyX3BvbHlsaW5lIiBzdHlsZT0iZmlsbDogbm9uZTsiIHBvaW50cz0iMTE1IDEwOSAxODcgNjkgMjU3IDEwOSIgLz48dGV4dCBmaWxsPSJibGFjayIgeD0iMjU3IiB5PSIzMyIgaWQ9ImU0X3RleHRlIiBzdHlsZT0iZm9udC1mYW1pbHk6IEFyaWFsOyBmb250LXNpemU6IDIwcHg7Ij48L3RleHQ+PHJlY3QgeD0iMTc5IiB5PSIxOSIgc3Ryb2tlPSJibGFjayIgaWQ9ImU1X3JlY3RhbmdsZSIgc3R5bGU9InN0cm9rZS13aWR0aDogMXB4OyIgd2lkdGg9IjE2IiBoZWlnaHQ9IjU0IiBmaWxsPSJraGFraSIgLz48L3N2Zz4=”);

 

3.

background-repeat:no-repeat; background-size:contain; background-position:center;

用绘制SVG 

http://www.drawsvg.org/drawsvg.html

 

转载于:https://www.cnblogs.com/GameEngine/p/7497070.html

今天的文章用SVG做background image分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/30099.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注