{"id":584,"date":"2024-12-28T17:43:02","date_gmt":"2024-12-28T09:43:02","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=584"},"modified":"2024-12-28T17:43:02","modified_gmt":"2024-12-28T09:43:02","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-svg-%e4%b8%ad%e4%b8%ba%e6%96%87%e6%9c%ac%e6%b7%bb%e5%8a%a0%e8%83%8c%e6%99%af%e9%a2%9c%e8%89%b2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/28\/%e5%a6%82%e4%bd%95%e5%9c%a8-svg-%e4%b8%ad%e4%b8%ba%e6%96%87%e6%9c%ac%e6%b7%bb%e5%8a%a0%e8%83%8c%e6%99%af%e9%a2%9c%e8%89%b2%ef%bc%9f\/","title":{"rendered":"\u5982\u4f55\u5728 SVG \u4e2d\u4e3a\u6587\u672c\u6dfb\u52a0\u80cc\u666f\u989c\u8272\uff1f"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5728 SVG \u4e2d\u4e3a\u6587\u672c\u6dfb\u52a0\u80cc\u666f\u989c\u8272\u4e0d\u662f\u76f4\u63a5\u652f\u6301\u7684\u529f\u80fd\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u6280\u5de7\u5b9e\u73b0\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u4e3a SVG \u4e2d\u7684\u6587\u672c\u6dfb\u52a0\u80cc\u666f\u989c\u8272\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u4f7f\u7528 <code>rect<\/code> \u5143\u7d20\u4f5c\u4e3a\u80cc\u666f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u7ed8\u5236\u4e00\u4e2a <code>rect<\/code> \u5143\u7d20\u4f5c\u4e3a\u6587\u672c\u7684\u80cc\u666f\u3002<code>rect<\/code> \u5143\u7d20\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u77e9\u5f62\uff0c\u5e76\u901a\u8fc7\u5b83\u7684\u586b\u5145\u989c\u8272\u4e3a\u6587\u672c\u63d0\u4f9b\u80cc\u666f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"400\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;!-- \u80cc\u666f\u77e9\u5f62 --&gt;\n    &lt;rect x=\"10\" y=\"10\" width=\"200\" height=\"40\" fill=\"lightblue\" \/&gt;\n\n    &lt;!-- \u6587\u672c --&gt;\n    &lt;text x=\"20\" y=\"40\" font-family=\"Arial\" font-size=\"24\" fill=\"black\"&gt;Hello, SVG!&lt;\/text&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>rect<\/code> \u5143\u7d20\u7ed8\u5236\u4e00\u4e2a\u77e9\u5f62\uff0c\u8bbe\u7f6e <code>x<\/code> \u548c <code>y<\/code> \u4e3a\u6587\u672c\u7684\u4f4d\u7f6e\uff0c<code>width<\/code> \u548c <code>height<\/code> \u6765\u63a7\u5236\u80cc\u666f\u7684\u5927\u5c0f\u3002<\/li>\n\n\n\n<li><code>fill=\"lightblue\"<\/code> \u8bbe\u7f6e\u77e9\u5f62\u7684\u586b\u5145\u989c\u8272\uff0c\u4f7f\u5176\u6210\u4e3a\u80cc\u666f\u989c\u8272\u3002<\/li>\n\n\n\n<li><code>text<\/code> \u5143\u7d20\u7ed8\u5236\u6587\u672c\uff0c<code>x<\/code> \u548c <code>y<\/code> \u8bbe\u7f6e\u6587\u672c\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u4f7f\u7528 <code>text<\/code> \u5143\u7d20\u7684 <code>stroke<\/code> \u548c <code>stroke-width<\/code> \u5c5e\u6027<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u5229\u7528 <code>stroke<\/code> \u5c5e\u6027\u4e3a\u6587\u672c\u6dfb\u52a0\u8fb9\u6846\uff0c\u901a\u8fc7\u5728\u6587\u672c\u7684\u8fb9\u6846\u5468\u56f4\u521b\u5efa\u4e00\u4e2a\u7c7b\u4f3c\u80cc\u666f\u7684\u6548\u679c\u3002\u4e0d\u8fc7\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5e76\u4e0d\u76f4\u63a5\u7ed9\u6587\u672c\u6dfb\u52a0\u80cc\u666f\u989c\u8272\uff0c\u800c\u662f\u901a\u8fc7\u6587\u672c\u7684\u8fb9\u7f18\u7ed8\u5236\u4e00\u79cd\u89c6\u89c9\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"400\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;text x=\"20\" y=\"40\" font-family=\"Arial\" font-size=\"40\" fill=\"white\" stroke=\"black\" stroke-width=\"2\"&gt;\n        Hello, SVG!\n    &lt;\/text&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>stroke=\"black\"<\/code> \u548c <code>stroke-width=\"2\"<\/code> \u5728\u6587\u672c\u5468\u56f4\u7ed8\u5236\u4e86\u4e00\u4e2a\u9ed1\u8272\u7684\u8fb9\u6846\uff0c\u8fd9\u770b\u8d77\u6765\u50cf\u662f\u6587\u672c\u7684\u80cc\u666f\u3002<\/li>\n\n\n\n<li><code>fill=\"white\"<\/code> \u8bbe\u7f6e\u6587\u672c\u7684\u989c\u8272\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u4f7f\u7528 <code>foreignObject<\/code> \u5143\u7d20\u5d4c\u5957 HTML<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u8981\u66f4\u52a0\u7075\u6d3b\u5730\u63a7\u5236\u80cc\u666f\u548c\u6587\u672c\u6837\u5f0f\uff08\u4f8b\u5982\u6587\u672c\u80cc\u666f\u662f\u6e10\u53d8\u6216\u4f7f\u7528\u590d\u6742\u7684\u6837\u5f0f\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>foreignObject<\/code> \u5143\u7d20\uff0c\u5b83\u5141\u8bb8\u4f60\u5d4c\u5165 HTML \u5143\u7d20\u5230 SVG \u4e2d\u3002\u5728 <code>foreignObject<\/code> \u5185\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5e38\u89c4 HTML \u548c CSS \u6765\u6dfb\u52a0\u80cc\u666f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"400\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;foreignObject x=\"10\" y=\"10\" width=\"200\" height=\"40\"&gt;\n        &lt;div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" style=\"background-color: lightblue; padding: 5px;\"&gt;\n            &lt;span style=\"font-family: Arial; font-size: 24px; color: black;\"&gt;Hello, SVG!&lt;\/span&gt;\n        &lt;\/div&gt;\n    &lt;\/foreignObject&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>foreignObject<\/code> \u5143\u7d20\u5305\u88f9\u4e00\u4e2a HTML <code>&lt;div><\/code>\uff0c\u5e76\u901a\u8fc7 CSS \u7ed9\u5b83\u6dfb\u52a0\u80cc\u666f\u989c\u8272\u548c\u5185\u8fb9\u8ddd\u3002<\/li>\n\n\n\n<li>\u5728 <code>&lt;div><\/code> \u4e2d\u653e\u7f6e\u4e86\u4e00\u4e2a <code>&lt;span><\/code> \u5143\u7d20\u6765\u663e\u793a\u6587\u672c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u4f7f\u7528 <code>filter<\/code> \u6dfb\u52a0\u80cc\u666f\u6548\u679c\uff08\u4e0d\u5e38\u7528\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136\u4e0d\u76f4\u63a5\u4e3a\u6587\u672c\u6dfb\u52a0\u80cc\u666f\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528 SVG \u6ee4\u955c\uff08<code>filter<\/code>\uff09\u6765\u521b\u5efa\u4e00\u4e9b\u6548\u679c\uff0c\u4f8b\u5982\u6587\u5b57\u7684\u9634\u5f71\u3001\u6a21\u7cca\u80cc\u666f\u7b49\uff0c\u4ee5\u6a21\u62df\u80cc\u666f\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"400\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;defs&gt;\n        &lt;filter id=\"f1\" x=\"0\" y=\"0\" width=\"200%\" height=\"200%\"&gt;\n            &lt;feOffset result=\"offOut\" in=\"SourceGraphic\" dx=\"10\" dy=\"10\" \/&gt;\n            &lt;feBlend in=\"SourceGraphic\" in2=\"offOut\" mode=\"normal\" \/&gt;\n        &lt;\/filter&gt;\n    &lt;\/defs&gt;\n\n    &lt;text x=\"20\" y=\"40\" font-family=\"Arial\" font-size=\"40\" fill=\"black\" filter=\"url(#f1)\"&gt;\n        Hello, SVG!\n    &lt;\/text&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u4e86 <code>filter<\/code> \u6765\u4e3a\u6587\u672c\u6dfb\u52a0\u9634\u5f71\u6548\u679c\uff0c\u521b\u5efa\u4e00\u79cd\u80cc\u666f\u7684\u89c6\u89c9\u6548\u679c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6700\u7b80\u5355\u7684\u65b9\u6cd5<\/strong> \u662f\u4f7f\u7528 <code>rect<\/code> \u5143\u7d20\u4f5c\u4e3a\u6587\u672c\u7684\u80cc\u666f\uff0c\u63a7\u5236\u5176\u5927\u5c0f\u548c\u586b\u5145\u989c\u8272\u6765\u8fbe\u5230\u76ee\u7684\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4f60\u9700\u8981\u66f4\u590d\u6742\u7684\u80cc\u666f\u6548\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>foreignObject<\/code> \u5143\u7d20\u5d4c\u5957 HTML \u5185\u5bb9\uff0c\u5b83\u5141\u8bb8\u4f60\u4f7f\u7528\u5e38\u89c4\u7684 HTML \u548c CSS \u6765\u8bbe\u7f6e\u6837\u5f0f\u3002<\/li>\n\n\n\n<li>\u5176\u4ed6\u65b9\u6cd5\uff0c\u5982\u4f7f\u7528 <code>stroke<\/code> \u6216 <code>filter<\/code>\uff0c\u4e5f\u53ef\u4ee5\u521b\u9020\u4e00\u4e9b\u89c6\u89c9\u4e0a\u7684\u80cc\u666f\u6548\u679c\uff0c\u5c3d\u7ba1\u5b83\u4eec\u5e76\u4e0d\u662f\u76f4\u63a5\u7ed9\u6587\u672c\u6dfb\u52a0\u80cc\u666f\u989c\u8272\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u822c\u6765\u8bf4\uff0c\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff08<code>rect<\/code> \u5143\u7d20\uff09\u662f\u6700\u5e38\u89c1\u4e14\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 SVG \u4e2d\u4e3a\u6587\u672c\u6dfb\u52a0\u80cc\u666f\u989c\u8272\u4e0d\u662f\u76f4\u63a5\u652f\u6301\u7684\u529f\u80fd\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u6280\u5de7\u5b9e\u73b0\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u4e3a SVG  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-584","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=584"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/584\/revisions"}],"predecessor-version":[{"id":585,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/584\/revisions\/585"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}