{"id":9539,"date":"2020-10-30T01:57:30","date_gmt":"2020-10-29T17:57:30","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9539"},"modified":"2020-10-31T23:31:03","modified_gmt":"2020-10-31T15:31:03","slug":"clip-path-sprites-icon","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2020\/10\/clip-path-sprites-icon\/","title":{"rendered":"\u4ecb\u7ecd\u4e00\u79cd\u5168\u65b0\u7684clipPath Sprites\u5c0f\u56fe\u6807\u6280\u672f"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9539\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9539<\/a><br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202010-clip-sprites.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/clip-sprites-cover.png\" width=\"480\" height=\"309\" alt=\"\u526a\u88c1\u56fe\u6807\u5408\u96c6\u6280\u672f\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<p>\u76ee\u524d\u6d41\u884c\u7684SVG\u5c0f\u56fe\u6807\u6280\u672f\u662fSVG Sprites\u6280\u672f\uff0c\u6b64\u6280\u672f\u62116\u5e74\u524d\u5c31\u7387\u5148\u5728\u56fd\u5185\u8fdb\u884c\u4e86\u4ecb\u7ecd\uff1a\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2014\/07\/introduce-svg-sprite-technology\/\">\u672a\u6765\u5fc5\u70ed\uff1aSVG Sprites\u6280\u672f\u4ecb\u7ecd<\/a>\u201d\uff0c\u8fd9\u91cc\u518d\u4ecb\u7ecd\u53e6\u5916\u4e00\u79cd\u540c\u6837\u9700\u8981\u7528\u5230SVG\u5143\u7d20\u7684Sprites\u6280\u672f\uff0c\u6211\u79f0\u4e4b\u4e3a\u201cclipPath Sprites\u6280\u672f\u201d\u3002<\/p>\n<h3>\u4e00\u3001\u5173\u4e8eclip-path\u4e0e\u5c0f\u56fe\u6807\u5b9e\u73b0<\/h3>\n<p>CSS <code>clip-path<\/code>\u5c5e\u6027\u9664\u4e86\u526a\u88c1\u5706\u3001\u591a\u8fb9\u5f62\u4e4b\u5916\uff0c\u8fd8\u652f\u6301<code>url()<\/code>\u51fd\u6570\u8bed\u6cd5\uff0c\u53ef\u4ee5\u628aSVG\u5143\u7d20\u4e2d\u7684\u8def\u5f84\u4f5c\u4e3a\u526a\u88c1\u8def\u5f84\u3002<\/p>\n<p>\u8bed\u6cd5\u793a\u610f\u5982\u4e0b\uff1a<\/p>\n<pre>.shape {\r\n    clip-path: url(#someId);\r\n}<\/pre>\n<p><code>someId<\/code>\u5c31\u662fSVG\u4e2d<code>&lt;clipPath&gt;<\/code>\u5143\u7d20\u7684ID\u503c\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;svg&gt;\r\n  &lt;clipPath <span style=\"color:#cd0000;\">id=\"someId\"<\/span>&gt;...&lt;\/clipPath&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u6848\u4f8b\u6f14\u793a\u4e0b\u8fd9\u79cd\u8bed\u6cd5\u7684\u6548\u679c\u3002<\/p>\n<p>\u5047\u8bbe\u6709\u5982\u4e0bSVG\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;svg width=\"50\" height=\"50\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\r\n    &lt;ellipse cx=\"25\" cy=\"25\" rx=\"20\" ry=\"10\"&gt;&lt;\/ellipse&gt;\r\n    &lt;rect x=\"15\" y=\"5\" width=\"20\" height=\"40\" rx=\"5\" ry=\"5\"&gt;&lt;\/rect&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>\u4f1a\u6709\u5982\u4e0b\u56fe\u6240\u793a\u7684\u59e8\u5988\u5dfe\u6548\u679c\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202007\/12-4_mask-image-origin-svg.png\" loading=\"lazy\" alt=\"SVG\u5143\u7d20\u56fe\u5f62\u6548\u679c\u793a\u610f\" width=\"125\" height=\"122\"><\/p>\n<p>\u6b64\u65f6\uff0c\u53ef\u4ee5\u628aSVG\u4e2d\u7684\u56fe\u5f62\u5143\u7d20\u5168\u90e8\u653e\u5728<code>&lt;clipPath&gt;<\/code>\u5143\u7d20\u4e2d\uff0c\u8fd9\u6837\uff0c\u5c31\u53ef\u4ee5\u628a\u4efb\u610f\u7684\u5143\u7d20\u526a\u88c1\u4e3a\u59e8\u5988\u5dfe\u7684\u5f62\u72b6\u4e86\u3002<\/p>\n<pre>&lt;svg width=\"0\" height=\"0\"&gt;\r\n  &lt;clipPath id=\"someId\"&gt;\r\n    &lt;ellipse cx=\"25\" cy=\"25\" rx=\"20\" ry=\"10\"&gt;&lt;\/ellipse&gt;\r\n    &lt;rect x=\"15\" y=\"5\" width=\"20\" height=\"40\" rx=\"5\" ry=\"5\"&gt;&lt;\/rect&gt;\r\n  &lt;\/clipPath&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>\u4f46\u662f\uff0c\u5b9e\u9645\u6d4b\u8bd5\u53d1\u73b0\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u53ea\u6709\u572850px*50px\u7684\u5143\u7d20\u4e2d\u6548\u679c\u624d\u662f\u6b63\u5e38\u7684\uff0c\u4e5f\u5c31\u662f\u526a\u88c1\u5143\u7d20\u7684\u5c3a\u5bf8\u9ed8\u8ba4\u9700\u8981\u548cSVG\u5143\u7d20\u56fe\u5f62\u5c3a\u5bf8\u4e00\u81f4\u624d\u884c\uff0c\u8fd9\u5c31\u6709\u4e9b\u5751\u7239\u4e86\uff0c\u597d\u5728SVG\u63d0\u4f9b\u4e86\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u9002\u7528\u4e8e\u4efb\u610f\u7684HTML\u5143\u7d20\u5c3a\u5bf8\u3002<\/p>\n<h4>\u65b9\u6cd51\uff1atransform\u7f29\u653eSVG<\/h4>\n<p>\u4f8b\u5982\u526a\u88c1\u7684HTML\u5143\u7d20\u7684\u5c3a\u5bf8\u662f20px*20px\uff0c\u539fSVG\u5c3a\u5bf8\u662f50px\uff0c\u56e0\u6b64\uff0c\u9700\u8981\u7f29\u653e40%\uff0c\u6b64\u65f6\u5c31\u6709\u5982\u4e0b\u6240\u793a\u7684SVG\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;svg width=\"0\" height=\"0\"&gt;\r\n  &lt;clipPath id=\"someId\"&gt;\r\n    &lt;ellipse <span style=\"color:#cd0000;\">transform=\"scale(0.4, 0.4)\"<\/span> cx=\"25\" cy=\"25\" rx=\"20\" ry=\"10\"&gt;&lt;\/ellipse&gt;\r\n    &lt;rect <span style=\"color:#cd0000;\">transform=\"scale(0.4, 0.4)\"<\/span> x=\"15\" y=\"5\" width=\"20\" height=\"40\" rx=\"5\" ry=\"5\"&gt;&lt;\/rect&gt;\r\n  &lt;\/clipPath&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>\u6b64\u65f6\uff0c\u5c31\u53ef\u4ee5\u628a20px*20px\u5927\u5c0f\u5143\u7d20\u526a\u88c1\u6210\u5bf9\u5e94\u89c4\u683c\u7684\u56fe\u5f62\u6548\u679c\u4e86\uff1a<\/p>\n<pre>.icon {\r\n    display: inline-block;\r\n    width: 20px; height: 20px;\r\n    background-color: deepskyblue;\r\n    clip-path: url(#someId);\r\n}<\/pre>\n<p>\u6b64\u65f6\u5c31\u6709\u5982\u4e0b\u56fe\u6240\u793a\u7684\u6548\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-29_233531.png\" width=\"228\" height=\"107\" alt=\"transform\u7f29\u653e\u4e0b\u7684\u56fe\u6807\u6548\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u65b9\u6cd52\uff1a\u8bbe\u7f6eclipPathUnits=&#8221;objectBoundingBox&#8221;<\/h4>\n<p>\u8bbe\u7f6e\u526a\u88c1\u4f4d\u7f6e\u662f\u57fa\u4e8e\u5bf9\u8c61\u7684\u5c3a\u5bf8\uff0c\u6b64\u65f6\uff0c\u9700\u8981SVG\u56fe\u5f62\u4e2d\u7684\u5750\u6807\u90fd\u4ee5\u6570\u503c1\u4e3a\u57fa\u51c6\u8fdb\u884c\u8ba1\u7b97\uff0c\u56e0\u6b64\uff0c\u901a\u5e38\u8def\u5f84\u6216\u8005\u53c2\u6570\u503c\u57fa\u672c\u4e0a\u90fd\u662f\u5c0f\u4e8e1\u7684\u6570\u503c\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;svg width=\"0\" height=\"0\"&gt;\r\n  &lt;clipPath id=\"someId\" clipPathUnits=\"objectBoundingBox\"&gt;\r\n    &lt;ellipse cx=\".5\" cy=\".5\" rx=\".4\" ry=\".2\"&gt;&lt;\/ellipse&gt;\r\n    &lt;rect x=\".3\" y=\".1\" width=\".4\" height=\".8\" rx=\".1\" ry=\".1\"&gt;&lt;\/rect&gt;\r\n  &lt;\/clipPath&gt;\r\n&lt;\/svg&gt;  <\/pre>\n<p>\u6b64\u65f6\uff0c\u526a\u88c1\u7684\u56fe\u5f62\u6548\u679c\u4f1a\u6309\u7167\u5143\u7d20\u7684\u7684\u5c3a\u5bf8\u8ba1\u7b97\uff0c\u65e0\u8bba\u56fe\u6807\u7684\u5c3a\u5bf8\u662f20px*20px\uff0c\u8fd8\u662f100px*100px\uff0c\u90fd\u4f1a\u6309\u7167\u8fd9\u4e2a\u5c3a\u5bf8\u8fdb\u884c\u526a\u88c1\u3002<\/p>\n<p>\u5b9e\u73b0\u7684\u6548\u679c\u5982\u4e0b\u622a\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-29_234020.png\" width=\"285\" height=\"105\" alt=\"\u56fe\u6807\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202010\/clip-path-svg-icon-demo.php\" rel=\"noopener\" target=\"_blank\">2\u79cd\u65b9\u6cd5\u5b9e\u73b0\u7684clip-path\u5c0f\u56fe\u6807\u526a\u88c1\u6548\u679cdemo<\/a><\/p>\n<p>\u65e0\u8bba\u662f<code>transform<\/code>\u7f29\u653e\uff0c\u8fd8\u662f<code>objectBoundingBox<\/code>\u91cd\u8ba1\u7b97\uff0c\u90fd\u53ef\u4ee5\u5b9e\u73b0\u4efb\u610f\u5c3a\u5bf8\u7684SVG\u526a\u88c1\u6548\u679c\u3002<\/p>\n<p>\u4e0b\u56fe\u662fFirefox\u6d4f\u89c8\u5668\u4e0b\u7684\u6548\u679c\u622a\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-29_234351.png\" width=\"353\" height=\"215\" alt=\"clip-path\u5b9e\u73b0\u5c0f\u56fe\u6807\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p><span class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4f53\u9a8c\u7cdf\u7cd5\u7684\u5783\u573e\u76d7\u7248\u7f51\u7ad9\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u539f\u6587\u83b7\u5f97\u5f88\u597d\u7684\u4f53\u9a8c\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=9539\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/span><\/p>\n<h4>\u5173\u4e8eIE\/Edge\u6d4f\u89c8\u5668<\/h4>\n<p>CSS\u4e2d\u67093\u4e2a\u5f88\u9ad8\u7ea7\u5c5e\u6027IE\u6d4f\u89c8\u5668\u4e5f\u662f\u652f\u6301\u7684\uff0c\u5206\u522b\u662f<code>clip-path<\/code>\u5c5e\u6027\uff0c<code>filter<\/code>\u5c5e\u6027\u548c<code>mask<\/code>\u5c5e\u6027\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e9b\u652f\u6301\u5176\u5b9e\u5e76\u4e0d\u662fCSS\u89c4\u8303\u4e2d\u7684\u90a3\u79cd\u652f\u6301\uff0c\u800c\u662fSVG\u5143\u7d20\u884d\u751f\u8fc7\u6765\u7684\u8bed\u6cd5\uff0c\u56e0\u4e3aIE\u6d4f\u89c8\u5668\u652f\u6301SVG\uff0c\u800cSVG\u4e2d\u6709\u4e00\u4e9b\u7279\u6027\u53ef\u4ee5\u5728CSS\u4e2d\u4f7f\u7528\uff0c\u56e0\u6b64\uff0cIE\u6d4f\u89c8\u5668\u4e5f\u652f\u6301\u4e86\u90e8\u5206\u9ad8\u7ea7CSS\u8bed\u6cd5\uff0c\u5c31\u597d\u50cfSVG\u4e2d\u7684<code>fill<\/code>\u548c<code>stroke<\/code>\u5c5e\u6027\u4e5f\u53ef\u4ee5\u5728IE\u4e2d\u4f7f\u7528\u4e00\u6837\u3002<\/p>\n<p>\u540c\u6837\u7684\uff0c<code>clip-path<\/code>\u5c5e\u6027\uff0c<code>filter<\/code>\u5c5e\u6027\u548c<code>mask<\/code>\u5c5e\u6027\u90fd\u662f\u4ec5\u652f\u6301<code>url()<\/code>\u8bed\u6cd5\uff0c\u5747\u6307\u5411SVG\u5143\u7d20\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u867d\u7136<code>clip-path:url(#someId)<\/code>\u5728IE\/Edge\u6d4f\u89c8\u5668\u4e0b\u8bed\u6cd5\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u662f\u4ec5\u4ec5\u4f5c\u7528\u5728SVG\u5143\u7d20\u4e0a\u624d\u6709\u6548\u679c\uff0c\u4e5f\u5c31\u662f\u4e0b\u9762\u7684HTML\u4ee3\u7801IE\u6d4f\u89c8\u5668\u662f\u6ca1\u6709\u6548\u679c\u7684\uff1a<\/p>\n<pre>&lt;i class=\"icon\"&gt;&lt;\/i&gt;<\/pre>\n<p>\u4f46\u662f\u4e0b\u9762\u7684\u4ee3\u7801\u5c31\u6709\u526a\u88c1\u6548\u679c\uff1a<\/p>\n<pre>&lt;svg width=\"20\" height=\"20\"&gt;\r\n  &lt;rect fill=\"deepskyblue\" class=\"icon\"&gt;&lt;\/rect&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u9700\u8981\u517c\u5bb9IE\u6d4f\u89c8\u5668\uff0c\u53ea\u8981\u628a\u666e\u901aHTML\u5143\u7d20\u6539\u4e3a\u4f7f\u7528SVG\u5143\u7d20\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h3>\u4e8c\u3001\u66f4\u8fdb\u4e00\u6b65\uff0cclipPath Sprites\u5c0f\u56fe\u6807\u6280\u672f<\/h3>\n<p>\u5728\u4f20\u7edf\u7684SVG Sprites\u4e2d\u4f7f\u7528\u7684\u662fSVG <code>&lt;use&gt;<\/code>\u5143\u7d20\u7684<code>href<\/code>\u5c5e\u6027\u503c\u6307\u5411<code>&lt;symbol&gt;<\/code>\u5143\u7d20\u7684id\u5c5e\u6027\uff0c\u563f\uff01\u5c82\u4e0d\u662f\u548c\u8fd9\u91cc\u7684\u5b9e\u73b0\u903b\u8f91\u672c\u8d28\u4e0a\u662f\u4e00\u6837\u7684\uff0c\u8fd9\u91cc\u662fCSS clip-path\u5c5e\u6027\u4e2d\u7684<code>url()<\/code>\u51fd\u6570\u503c\u6307\u5411<code>&lt;clipPath&gt;<\/code>\u5143\u7d20\u7684id\u5c5e\u6027\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u7406\u8bba\u4e0a\uff0c\u4f20\u7edfSVG Sprites\u5408\u5e76\u90a3\u4e00\u5957\u4e1c\u897f\u4e5f\u662f\u53ef\u4ee5\u7528\u5728clipPath Sprites\u5408\u5e76\u4e2d\u7684\u3002<\/p>\n<p>\u53d7\u6b64idea\u7684\u542f\u53d1\uff0c\u6211\u5c31\u628a\u6211\u4e4b\u524d\u5236\u4f5c\u7684SVG\u538b\u7f29\u5408\u5e76\u5de5\u5177\u5347\u7ea7\u4e86\u4e0b\uff0c\u589e\u52a0\u4e86clipPath Sprites\u5408\u5e76\u529f\u80fd\uff08\u9009\u62e9\u7684\u662f<code>transform<\/code>\u7f29\u653e\uff0c\u56e0\u4e3a\u66f4\u5bb9\u6613\u5b9e\u73b0[\u6342\u8138]\uff09\uff0c\u53d1\u73b0\u8fd9\u4e2a\u6280\u672f\u5b8c\u5168\u53ef\u884c\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/sp\/svgo\/\" rel=\"noopener\" target=\"_blank\" class=\"a_link\">\u5347\u7ea7\u540e\u7684SVG\u5728\u7ebf\u538b\u7f29\u5408\u5e76\u5de5\u5177<\/a><\/p>\n<p>\u4ece\u8fd9\u4e2a\u6211\u505a\u7684<a href=\"https:\/\/www.zhangxinxu.com\/sp\/icon\/\" rel=\"noopener\" target=\"_blank\">SVG Sprites\u8fd8\u539f\u5de5\u5177<\/a>\u4e2d\u4e0b\u8f7d\u51e0\u4e2a\u6bd4\u8f83\u987a\u773c\u7684\u56fe\u6807\uff0c\u7136\u540e\u62d6\u8fdb\u53bb\u2014\u2014<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-30_005955.png\" width=\"668\" height=\"353\" alt=\"\u56fe\u6807\u62d6\u62fd\u8fdb\u53bb\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5728\u9875\u9762\u7684\u6700\u4e0b\u65b9\u5c31\u53ef\u4ee5\u770b\u5230\u5408\u5e76\u540e\u7684clipPath Sprites\u4ee3\u7801\u4e86\uff0c\u5982\u4e0b\u622a\u56fe\u793a\u610f\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-30_010145.png\" width=\"654\" height=\"430\" alt=\"clipPath Sprites\u4ee3\u7801\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u70b9\u51fb\u590d\u5236\u6216\u4e0b\u8f7d\u6309\u94ae\uff0c\u628a\u8f93\u5165\u6846\u4e2d\u7684SVG\u4ee3\u7801\u590d\u5236\u5230\u9875\u9762\u4e2d\uff0c\u6b64\u65f6\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528CSS <code>clip-path<\/code>\u5c5e\u6027\u5b9e\u73b0\u5404\u5f0f\u5404\u6837\u7684\u5c0f\u56fe\u6807\u6548\u679c\u4e86\u3002<\/p>\n<pre>&lt;svg version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"0\" height=\"0\" style=\"position:absolute;\"&gt;\r\n    &lt;clipPath id=\"eye\"&gt;&lt;path transform=\"scale(0.034724, 0.0390625)\" d=\"...\"\/&gt;&lt;\/clipPath&gt;\r\n    &lt;clipPath id=\"paper-plane\"&gt;&lt;path transform=\"scale(0.0390625, 0.0390625)\" d=\"...\"\/&gt;&lt;\/clipPath&gt;\r\n    &lt;clipPath id=\"comment\"&gt;&lt;path transform=\"scale(0.0390625, 0.0390625)\" d=\"...\"\/&gt;&lt;\/clipPath&gt;\r\n&lt;\/svg&gt;  <\/pre>\n<p>\u4f8b\u5982\u6709\u5982\u4e0b\u6240\u793a\u7684HTML\u548cCSS\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;ul id=\"ul\"&gt;\r\n    &lt;li&gt;&lt;i class=\"icon\" style=\"--clipPath:url(#paper-plane)\"&gt;&lt;\/i&gt;\u5206\u4eab&lt;\/li&gt;\r\n    &lt;li&gt;&lt;i class=\"icon\" style=\"--clipPath:url(#eye)\"&gt;&lt;\/i&gt;\u9884\u89c8&lt;\/li&gt;\r\n    &lt;li&gt;&lt;i class=\"icon\" style=\"--clipPath:url(#comment)\"&gt;&lt;\/i&gt;\u8bc4\u8bba&lt;\/li&gt;\r\n&lt;\/ul&gt;<\/pre>\n<pre>.icon {\r\n    display: inline-block;\r\n    width: 20px; height: 20px;\r\n    background-color: currentColor;\r\n    -webkit-clip-path: var(--clipPath);\r\n    clip-path: var(--clipPath);\r\n    vertical-align: middle;\r\n    margin-right: 1ch;\r\n}<\/pre>\n<p>\u6b64\u65f6\u5c31\u6709\u5982\u4e0b\u56fe\u6240\u793a\u7684\u5c0f\u56fe\u6807\u6548\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-30_010631.png\" width=\"130\" height=\"112\" alt=\"\u5c0f\u56fe\u6807\u6548\u679c\u5b9e\u73b0\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u6709\u6f14\u793a\u7684\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202010\/clip-path-svg-sprites-demo.php\" rel=\"noopener\" target=\"_blank\">SVG clipPath\u5408\u5e76\u56fe\u6807\u6548\u679cdemo<\/a><\/p>\n<p>\u7531\u4e8e\u662f\u901a\u8fc7\u526a\u88c1\u5b9e\u73b0\u7684\uff0c\u56e0\u6b64\u5b9e\u73b0\u7684\u56fe\u6807\u6548\u679c\u652f\u6301\u4efb\u610f\u53d8\u8272\uff0c\u5982\u4e0bGIF\u5f55\u5c4f\u793a\u610f\uff08\u70b9\u51fb\u64ad\u653e317K\uff09\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/icon-color-change.png\" width=\"337\" height=\"428\" alt=\"\u989c\u8272\u53d8\u5316GIF\u5f55\u5c4f\u793a\u610f\" class=\"alignnone size-medium\" onclick=\"this.src=this.src.replace('.png', '.gif')\" \/><\/p>\n<p>\u4e5f\u53ef\u4ee5\u662f\u6e10\u53d8\u6548\u679c\uff08\u6539\u6210\u80cc\u666f\u6e10\u53d8\u5373\u53ef\uff09\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>.icon {\r\n    background: linear-gradient(deepskyblue, deeppink);\r\n    ...\r\n}<\/pre>\n<p>\u6e10\u53d8\u6548\u679c\u5982\u4e0b\u622a\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-30_011925.png\" width=\"141\" height=\"118\" alt=\"\u6e10\u53d8\u622a\u56fe\u6548\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u628a\u7167\u7247\u526a\u88c1\u6210\u56fe\u6807\u6a21\u677f\uff0c\u6216\u8005\u662f\u4efb\u610f\u7684\u5143\u7d20\uff0c\u6309\u94ae\u3001\u6587\u5b57\u7b49\u90fd\u53ef\u4ee5\u526a\u88c1\u6210\u5c0f\u56fe\u6807\u7684\u6837\u5b50\uff0c\u975e\u5e38\u7075\u6d3b\u3002<\/p>\n<h4>\u5bf9\u6bd4\u4f20\u7edfSVG Sprites\u6280\u672f<\/h4>\n<table border=\"0\" width=\"100%\" class=\"params_table\" cellspacing=\"1\">\n<thead>\n<tr>\n<th><\/th>\n<th>\u4f20\u7edfSVG Sprites<\/th>\n<th>clipPath Sprites<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>\u77e2\u91cf<\/td>\n<td>\u2714<\/td>\n<td>\u2714<\/td>\n<\/tr>\n<tr>\n<th>\u989c\u8272\u53ef\u53d8<\/td>\n<td>\u2714<\/td>\n<td>\u2714<\/td>\n<\/tr>\n<tr>\n<th>\u652f\u6301\u6e10\u53d8<\/td>\n<td>\u2718<\/td>\n<td>\u2714<\/td>\n<\/tr>\n<tr>\n<th>\u6807\u7b7e<\/td>\n<td>svg&gt;use<\/td>\n<td>\u4efb\u610fHTML\u6807\u7b7e\uff08IE\u9664\u5916\uff09<\/td>\n<\/tr>\n<tr>\n<th>\u517c\u5bb9\u6027<\/td>\n<td>IE9+<\/td>\n<td>IE9+\uff08IE\u9700\u4f7f\u7528SVG\u5143\u7d20\uff09<\/td>\n<\/tr>\n<tr>\n<th>\u5c3a\u5bf8\u63a7\u5236<\/td>\n<td>\u7075\u6d3b<\/td>\n<td>transform\u65b9\u6cd5\u53d7\u9650 | clipPathUnits\u65b9\u6cd5\u7075\u6d3b<\/td>\n<\/tr>\n<tr>\n<th>\u5de5\u5177<\/td>\n<td>\u4e30\u5bcc \u2714<\/td>\n<td>\u8d77\u6b65\u4e2d\u2026\u2026<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6574\u4f53\u6765\u770b\uff0cclipPath Sprites\u6280\u672f\u7684\u4f18\u52bf\u66f4\u5f3a\uff0c\u5c24\u5176\u5728\u79fb\u52a8\u7aef\u5f00\u53d1\u4e2d\uff0c\u53ea\u8981\u540e\u671f\u6709\u8f6c\u6362\u5de5\u5177\u53ef\u4ee5\u628a\u6240\u6709\u7684SVG\u56fe\u6807\u8def\u5f84\u8f6c\u6210clipPathUnits\u4e3aobjectBoundingBox\u6a21\u5f0f\u7684\u6570\u503c\uff0c\u90a3\u4e48clipPath Sprites\u6280\u672f\u51e0\u4e4e\u5c31\u6ca1\u6709\u4efb\u4f55\u7f3a\u9677\uff0c\u53d6\u4ee3\u4f20\u7edf\u7684SVG Sprites\u5c0f\u56fe\u6807\u6280\u672f\u5e94\u8be5\u4e0d\u6210\u95ee\u9898\u3002<\/p>\n<h3>\u4e09\u3001\u809d\u4e0d\u52a8\u7684\u7ed3\u8bed<\/h3>\n<p>\u672c\u6708\u7206\u66f411\u7bc7\u6280\u672f\u6587\u7ae0\uff0c10\u5e74\u6765\u65b0\u9ad8\uff0c\u4e3a\u4ec0\u4e48\u9ad8\u4ea7\u56db\u6bcd\u732a\u5462\uff1f\u56e0\u4e3a\u300aCSS\u65b0\u4e16\u754c\u300b\u8fd9\u672c\u4e66\u4ea4\u7a3f\u4e86\uff0c\u6709\u65f6\u5019\u66f4\u65b0\u535a\u5ba2\u4e86\uff0c\u4e8e\u662f\u79ef\u6512\u7684\u6587\u7ae0\u4e00\u6b21\u6027\u7206\u53d1\u4e86\uff0c\u4e0d\u8fc7\u4e5f\u5bfc\u81f4\u8fd9\u4e2a\u6708\u5929\u5929\u5f88\u665a\u7761\uff0c\u5b9e\u5728\u6709\u4e9b\u809d\u4e0d\u52a8\u4e86\u3002<\/p>\n<p>\u56de\u5230\u6587\u7ae0\u8fd9\u91cc\uff0cclipPath Sprites\u6280\u672f\u662f\u81ea\u5df1\u5199CSS <code>clip-path<\/code>\u7ae0\u8282\u7a81\u7136\u7684\u7075\u611f\uff0c\u6211\u67e5\u4e86\u4e0b\u56fd\u5185\u5916\u7684\u8d44\u6599\uff0c\u6709\u4f7f\u7528<code>clip-path<\/code>\u5b9e\u73b0\u5c0f\u56fe\u6807\u6548\u679c\u7684\u6848\u4f8b\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u53d1\u73b0\u8c01\u628a\u5c0f\u56fe\u6807\u5168\u90e8\u6253\u5305\u5728\u4e00\u8d77\u7684\u6848\u4f8b\uff0c\u56e0\u6b64\uff0c\u672c\u6587\u7684clipPath Sprites\u6280\u672f\u53ef\u4ee5\u7b97\u662f\u4e00\u4e2a\u9996\u521b\u7684\u6280\u672f\u5427\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u4e5f\u662f\u6700\u8fd1\u521a\u6298\u817e\u51fa\u6765\u7684\uff0c\u8fd8\u6ca1\u6709\u5728\u751f\u6210\u73af\u5883\u4f7f\u7528\uff0c\u56e0\u6b64\uff0c\u662f\u5426\u6709\u4ec0\u4e48\u5751\u8fd8\u4e0d\u5f97\u800c\u77e5\uff0c\u4e0d\u8fc7\u6309\u7167\u6211\u957f\u671f\u4ee5\u6765\u4f7f\u7528<code>clip-path<\/code>\u7684\u7ecf\u9a8c\u6765\u770b\uff0c\u5e94\u8be5\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c<code>clip-path<\/code>\u4e00\u76f4\u662f\u4e00\u4e2a\u8fd0\u884c\u975e\u5e38\u7a33\u5065\u7684CSS\u5c5e\u6027\uff0c\u5728\u79fb\u52a8\u7aef\u517c\u5bb9\u6027\u4e5f\u975e\u5e38\u597d\u3002<\/p>\n<p>\u6211\u8fd1\u671f\u4f1a\u5728\u5408\u9002\u7684\u9879\u76ee\u4e2d\u5c1d\u8bd5\u8fd9\u79cd\u56fe\u6807\u6280\u672f\uff0c\u4e4b\u540e\u6709\u53d8\u5316\u4f1a\u8fdb\u4e00\u6b65\u66f4\u65b0\u3002<\/p>\n<p>OK\uff0c\u7ed3\u8bed\u5c31\u8bf4\u8fd9\u4e48\u591a\u3002<\/p>\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u672c\u6587\u5185\u5bb9\u786e\u5b9e\u6709\u70b9\u6599\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u4e5f\u6b22\u8fce\u4ee5\u8bc4\u8bba\u65b9\u5f0f\u8fdb\u884c\u4ea4\u6d41\uff0c\u8865\u5145\u6211\u4e0d\u77e5\u9053\u7684\u4fe1\u606f\uff0c\u6216\u8005\u6307\u51fa\u6587\u7ae0\u6709\u8868\u8ff0\u4e0d\u51c6\u786e\u7684\u5730\u65b9\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9539\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9539<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/clip-sprites-cover.png\" width=\"160\" height=\"103\" alt=\"\u526a\u88c1\u56fe\u6807\u5408\u96c6\u6280\u672f\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e00\u79cd\u5168\u65b0\u7684SVG\u56fe\u6807\u5408\u96c6\u6280\u672f\uff0c\u6709\u522b\u4e8e\u4f20\u7edf\u7684&lt;symbol&gt;\u5143\u7d20\uff0c\u8fd9\u91cc\u4f7f\u7528\u7684\u662f&lt;clipPath&gt;\u5143\u7d20\uff0c\u914d\u5408CSS clip-path\u5c5e\u6027\u4f7f\u7528\uff0c\u4f18\u52bf\u5728\u4e8eHTML\u6807\u7b7e\u4efb\u610f\uff0cUI\u6837\u5f0f\u4efb\u610f\uff0c\u672c\u6587\u5185\u5bb9\u4e00\u5b9a\u4f1a\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,895],"tags":[959,960,1687,1685,368,1078,1686,642,929,722],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9539"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=9539"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9539\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=9539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=9539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=9539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}