svg用作背景图

svg用做背景图的几种方式

1. 直接使用

background: url('data:image/svg+xml;charset=utf-8,<svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"><g> <rect stroke="#000" transform="rotate(44.7 5,5)" height="6" width="6" y="2" x="2" stroke-width="0" fill="#f00"/></g></svg>') no-repeat 50% 50% / 100% 100%;

2. 转为base64后使用

background-image: url('data:image/svg+xml;base64,PCEtLSDlm77moIfvvJrmlofku7YgLS0+DQo8IS0tIDxz...');

3. 外置引用

background-image: url(test.svg);

原文地址:https://www.cnblogs.com/qiang-ling/p/9511233.html