url引用格式:url('data:image/svg+xml;base64')
实例:
准备好SVG文件
源码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
body{ /*base64代码--直接复制SVG文件里的所有代码*/
background: rgb(255,255,255) url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 200 100' preserveAspectRatio='none'><defs><radialGradient id='rg1' cx='0%' cy='0%' r='100%' fx='0%' fy='0%'><stop offset='0%' style='stop-color: #a480ff; stop-opacity: 0.5' /><stop offset='100%' style='stop-color: #a480ff; stop-opacity:0' /></radialGradient><radialGradient id='rg2' cx='100%' cy='0%' r='100%' fx='100%' fy='0%'><stop offset='0%' style='stop-color: #ff8f83; stop-opacity: 0.5' /><stop offset='100%' style='stop-color: #ff8f83; stop-opacity:0' /></radialGradient></defs><polygon points='0,0 125,0 125,100 0,100' style='fill: url(#rg1);' /><polygon points='75,0 200,0 200,100 75,100' style='fill: url(#rg2);' /></svg>") no-repeat;
-webkit-background-size: 100% auto;
background-size: 100% auto;
}
</style>
<body>
</body>
</html>
效果: