{"id":4501,"date":"2014-12-22T01:33:21","date_gmt":"2014-12-21T17:33:21","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4501"},"modified":"2018-06-16T00:08:50","modified_gmt":"2018-06-15T16:08:50","slug":"css3-svg-clip-path","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2014\/12\/css3-svg-clip-path\/","title":{"rendered":"CSS3\/SVG clip-path\u8def\u5f84\u526a\u88c1\u906e\u7f69\u5c5e\u6027\u7b80\u4ecb"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4501\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=4501<\/a><\/p>\n<h3>\u4e00\u3001SVG\u5c5e\u6027\u548cCSS3\u5c5e\u6027\u5343\u4e1d\u4e07\u7f15\u7684\u5173\u7cfb<\/h3>\n<p>CSS3\u65b0\u589e\u5c5e\u6027\u9664\u4e86\u6211\u4eec\u73b0\u5728\u7528\u7684\u6bd4\u8f83\u591a\u7684<code>border-radius<\/code>, <code>box-shadow<\/code>, <code>gradient<\/code>, <code>...<\/code>\u4e4b\u7c7b\uff0c\u8fd8\u6709\u5f88\u91cd\u8981\u7684\u4e00\u4e2a\u5206\u652f\uff1a<strong>SVG\u5c5e\u6027\u5bb6\u65cf\uff01<\/strong><\/p>\n<p>\u6240\u8c13\u300cSVG\u5c5e\u6027\u5bb6\u65cf\u300d\u662f\u6307\u539f\u672cSVG\u7684\u6807\u7b7e\u5c5e\u6027\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528CSS\u8bbe\u7f6e\u3002<\/p>\n<p>\u6bd4\u65b9\u8bf4\uff0c\u4e4b\u524d\u4ecb\u7ecd\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/2014\/07\/introduce-svg-sprite-technology\/\">SVG Sprites\u6280\u672f<\/a>\u201d\u65f6\u5019\u63d0\u5230\u7684<code>fill<\/code>\u5c5e\u6027\uff0c\u4ee5\u53ca\u4e4b\u540e\u4e13\u95e8\u5199\u4e86\u7bc7\u6587\u7ae0\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/2014\/07\/svg-sprites-fill-color-currentcolor\/\">SVG\u56fe\u6807\u989c\u8272\u6587\u5b57\u822c\u7ee7\u627f\u4e0e\u586b\u5145<\/a>\u201d\u8bb2CSS\u4e2d\u4f7f\u7528SVG\u7684<code>fill<\/code>\u5c5e\u6027\u5b9e\u73b0\u4e00\u4e9b\u6548\u679c\u3002\u8fd8\u6709\u5f88\u7ecf\u5178\u7684\u5728CSS\u4e2d\u4f7f\u7528 <code>stroke-dasharray<\/code>\u4ee5\u53ca<code>stroke-dashoffset<\/code>\u5b9e\u73b0\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4089\">\u5e05\u6c14\u7684SVG\u8def\u5f84\u63cf\u8fb9\u52a8\u753b\u6548\u679c<\/a>\u201d\u4ee5\u53ca\u4ee5\u540e\u4f1a\u4ecb\u7ecd\u7684<code>mask<\/code>\u5c5e\u6027\u7b49\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"589\" height=\"224\" alt=\"\u540d\u5b57\u7ebf\u6761gif\u52a8\u753b\" class=\"mt10\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201404\/2014-04-08_16-30-19.gif\"><\/p>\n<p>\u800c\u672c\u6587\u7684<code>clip-path<\/code>\u4e5f\u662f\u5176\u4e2d\u4e00\u5458\uff0c\u867d\u7136\u624d\u9732\u5c16\u5c16\u89d2\uff0c\u76f8\u4fe1\u4ee5\u540e\u4f1a\u50cf\u8def\u8fb9\u7684\u91ce\u82b1\u5230\u5904\u7efd\u653e\uff0c\u8fd9\u91cc\u5148\u62a2\u4e2a\u5148\u673a\uff0c\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u3002<\/p>\n<h3>\u4e8c\u3001SVG\u4e2d\u7684clip-path<\/h3>\n<p>SVG\u4e2d\uff0c\u6709\u4e2a\u540d\u53eb<code>&lt;clipPath&gt;<\/code>\u7684\u5143\u7d20\uff0c\u4eba\u5982\u5176\u540d\uff0c\u5176\u4e13\u95e8\u7528\u6765\u5b9a\u4e49\u526a\u88c1\u8def\u5f84\u7684\u3002\u4e3e\u4e2a\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;defs<span style=\"color:green;\">>&lt;!-- \u5b9a\u4e49 --><\/span>\n  &lt;clipPath id=\"clipPath\"><span style=\"color:green;\">&lt;!-- \u5b9a\u4e49\u526a\u88c1\u8def\u5f84 --><\/span>\n      &lt;rect x=\"0\" y=\"0\" width=\"80\" height=\"80\" \/><span style=\"color:green;\">&lt;!-- \u8def\u5f84\u8be6\u7ec6 --><\/span>\n  &lt;\/clipPath>\n&lt;\/defs>\n<\/pre>\n<\/div>\n<p>\u4e0a\u9762\u7684<code>&lt;clipPath&gt;<\/code>\u5b9a\u4e49\u4e86\u4e00\u4e2a<code>80*80<\/code>\u7684\u77e9\u5f62\u526a\u88c1\u8def\u5f84\u3002OK\uff0c\u5047\u8bbe\u73b0\u5728SVG\u4e2d\u6709\u4e2a\u5706\uff0cSVG\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;circle cx=\"60\" cy=\"60\" r=\"50\" fill=\"#34538b\" \/><\/pre>\n<\/div>\n<p>\u6309\u7167\u6211\u4eec\u6d45\u663e\u7684\u8ba4\u8bc6\uff0c\u5e94\u8be5\u4f1a\u51fa\u73b0\u4e00\u4e2a\u586b\u5145\u67d0\u79cd\u989c\u8272\u7684\u5706\uff0c\u7c7b\u4f3c\u4e0b\u622a\u56fe\u6548\u679c\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201412\/2014-12-21_212441.png\" width=\"304\" height=\"152\" alt=\"SVG\u4e00\u4e2a\u666e\u901a\u7684\u5706\" class=\"mt10\" \/><\/p>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u6b64\u65f6\u8be5\u5706\u540c\u65f6\u8bbe\u7f6e\u4e86<code>clip-path<\/code>\u5c5e\u6027\uff0c\u4e14\u503c\u6307\u5411\u7684\u5c31\u662f\u4e0a\u9762\u5b9a\u4e49\u7684\u526a\u88c1\u8def\u5f84<code>#clipPath<\/code>\u5462\uff1f<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;circle cx=\"60\" cy=\"60\" r=\"50\" fill=\"#34538b\" <span style=\"color:#cd0000;\">clip-path=\"url(#clipPath)\"<\/span> \/><\/pre>\n<\/div>\n<p>\u5219\uff0c\u5341\u4e94\u7684\u5706\u88ab\u526a\u88c1\u6210\u4e86\u94f6\u674f\u53f6\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201412\/2014-12-21_212459.png\" width=\"303\" height=\"149\" alt=\"\u526a\u88c1\u4e4b\u540e\u7684\u6548\u679c\" class=\"mt10\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201412\/svg-clip-path-rect.html\" target=\"_blank\">SVG clipPath\u77e9\u5f62\u526a\u88c1\u793a\u610fdemo<\/a><\/p>\n<p>\u8ddf<code>&lt;g&gt;<\/code>, <code>&lt;symbol&gt;<\/code>\u7b49\u5143\u7d20\u7c7b\u4f3c\uff0c<code>&lt;clipPath&gt;<\/code>\u5143\u7d20\u91cc\u9762\u9664\u4e86<code>rect<\/code>\u5143\u7d20, \u8fd8\u53ef\u4ee5\u662f<code>circle<\/code>, <code>ellipse<\/code>, <code>line<\/code>, <code>polyline<\/code>, <code>polygon<\/code>, <code>...<\/code>\u7b49\u7b49\uff0c\u751a\u81f3\u662f<code>text<\/code>\u6587\u672c\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>&lt;svg>\n    &lt;defs>\n        &lt;clipPath id=\"clipPath\">\n            &lt;<span style=\"color:#cd0000;\">text<\/span> x=\"10\" y=\"50\" style=\"font-size: 20px;\">\u4e00\u6b65\u4e4b\u9065&lt;\/text>\n        &lt;\/clipPath>\n    &lt;\/defs>\n    &lt;g <span style=\"color:#cd0000;\">style=\"clip-path: url(#clipPath);\"<\/span>>\n        &lt;circle cx=\"60\" cy=\"60\" r=\"50\" fill=\"#34538b\" \/>\n        &lt;rect x=\"0\" y=\"0\" width=\"60\" height=\"90\" style=\"fill:#cd0000;\"\/>\n    &lt;\/g>\n&lt;\/svg><\/pre>\n<\/div>\n<p>\u76ee\u524dChrome\u6d4f\u89c8\u5668\u4e0b\u7684\u6587\u5b57\u526a\u88c1\u6781\u5177\u9a6c\u8d5b\u514b\u98ce\u683c\uff0c\u7c7b\u4f3c\u4e0b\u9762\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201412\/2014-12-21_222556.png\" width=\"300\" height=\"155\" alt=\"Chrome\u6d4f\u89c8\u5668\u4e0b\u7684\u6587\u5b57\u526a\u88c1\" class=\"alignnone\" \/><\/p>\n<p>\u800c\u5176\u4ed6\u6d4f\u89c8\u5668\uff0c\u4f8b\u5982IE\u6d4f\u89c8\u5668\uff0c\u5219\u8868\u73b0\u6b63\u5e38\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201412\/2014-12-21_222613.png\" width=\"259\" height=\"140\" alt=\"IE\u6d4f\u89c8\u5668\u4e0b\u6587\u5b57\u526a\u88c1\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201412\/svg-clip-path-text.html\" target=\"_blank\">SVG clipPath\u6587\u672c\u526a\u88c1\u793a\u610fdemo<\/a><\/p>\n<p><span class=\"s\">\/\/zxx: \u5982\u679c\u88ab\u526a\u88c1\u7684\u662f\u56fe\u7247\uff0c\u5219\u6211\u4eec\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6587\u5b57\u906e\u7f69\u56fe\u7247\u6548\u679c\u4e86\uff0c\u70b9\u5230\u4e3a\u6b62\uff0c\u6211\u5c31\u5e2e\u5230\u8fd9\u91cc\u4e86~ <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/4.gif\" align=\"absmiddle\"><\/span><\/p>\n<p>\u4e0a\u9762\u5217\u4e3e\u4e86\u201c\u77e9\u5f62\u526a\u88c1\u201d\u548c\u201c\u6587\u672c\u526a\u88c1\u201d\u4e24\u4e2a\u4f8b\u5b50\uff0c\u5927\u5bb6\u6709\u6728\u6709\u53d1\u73b0\u5728\u5e94\u7528<code>clip-path<\/code>\u5c5e\u6027\u7684\u65f6\u5019\u6709\u4ec0\u4e48\u5dee\u522b\uff1f<\/p>\n<p>\u554a~\u8fd9\u4f4d\u540c\u5b66\u773c\u775b\u5f88\u5c16\uff0c\u4e00\u773c\u5c31\u770b\u51fa\u6765\uff0c\u524d\u8005\u76f4\u63a5\u6807\u7b7e\u5c5e\u6027\uff1b\u540e\u8005\u5219\u662f<code>style<\/code>\u6837\u5f0f\u8bbe\u7f6e\uff08\u7ea2\u8272\u9ad8\u4eae\u4ee3\u7801\uff09\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>clip-path=\"url(#clipPath)\"\n\nstyle=\"clip-path: url(#clipPath);\"<\/pre>\n<\/div>\n<p><code>style<\/code>\u53ef\u4ee5\u8bbe\u7f6e\uff0c\u4e5f\u5c31\u662f\u610f\u5473\u7740\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5728CSS\u4ee3\u7801\u4e2d\u4f7f\u7528<code>clip-path<\/code>\u5c5e\u6027\uff01<\/p>\n<h3>\u4e09\u3001CSS\u4e2d\u7684clip-path<\/h3>\n<p><strong>1. clip-path\u4e0eclip<\/strong><br \/>\nCSS\u672c\u8eab\u5c31\u6709\u526a\u88c1\u5c5e\u6027<code>clip<\/code>, \u5177\u4f53\u53ef\u53c2\u800311\u5e74\u6211\u5199\u7684\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/2011\/04\/css-clip-rect\/\">CSS clip:rect\u77e9\u5f62\u526a\u88c1\u529f\u80fd\u53ca\u4e00\u4e9b\u5e94\u7528\u4ecb\u7ecd<\/a>\u201d\u4e00\u6587\uff0c\u4e0d\u8fc7\uff0c\u9700\u8981\u5728<code>position<\/code>\u4e3a<code>absolute<\/code>\u540e\u8005<code>fixed<\/code>\u65f6\u5019\u624d\u6709\u4f5c\u7528\u3002<\/p>\n<p>\u90a3\u672c\u6587\u4e3b\u89d2<code>clip-path<\/code>\u4e0e<code>clip<\/code>\u53c8\u662f\u4ec0\u4e48\u5173\u7cfb\u5462\uff1f<\/p>\n<p>\u636e\u8bf4\u7531\u4e8e<code>clip<\/code>\u662f\u6276\u4e0d\u8d77\u7684\u963f\u6597\uff0c\u4e8e\u662fW3\u5f03\u4e4b\uff0c\u5f00\u59cb\u57f9\u517b<code>clip-path<\/code>\u4e3a\u65b0\u4e00\u4ee3\u7684\u4ee3\u8a00\u4eba\u3002\u5b9e\u9645\u4e0a\uff0c<code>clip<\/code>\u5728\u53ef\u7528\u6027\u9690\u85cf\u9886\u57df\u662f\u72ec\u9886\u98ce\u9a9a\u7684\uff01\u597d\u5427\uff0c\u65e2\u7136\u7fa4\u4f17\u603b\u662f\u8ff7\u604b\u4e8e\u6d6e\u4e8e\u8868\u9762\u7684\u4e1c\u897f\uff0c<code>clip-path<\/code>\u80af\u5b9a\u4e0d\u4f1a\u50cf<code>clip<\/code>\u4e00\u6837\uff0c\u6162\u6162\u53d8\u6210\u6cbe\u6ee1\u7070\u5c18\u7684\u534a\u5c9b\u94c1\u76d2\u7684\u3002<\/p>\n<p>\u81ea\u7136\uff0c<code>clip-path<\/code>\u8981\u60f3\u53d6\u4ee3<code>clip<\/code>\uff0c\u7b2c1\u6b65\u5c31\u662f\u8981\u5b9e\u73b0<code>clip<\/code>\u5e94\u6709\u7684\u529f\u80fd\uff0c\u65b9\u6cd5\u503c\u6709\u6240\u53d8\u5316\uff0c\u4e0d\u662f<code>rect<\/code>\u4e86\uff0c\u800c\u662f<code>inset<\/code>. \u770b\u4e0b\u9762\u7684\u4ee3\u7801\u5bf9\u6bd4\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.clip-me {  \n  <span style=\"color:green;\">\/* \u88ab\u629b\u5f03\u7684\u526a\u88c1 *\/<\/span>\n  position: absolute; <span style=\"color:green;\">\/* absolute\u6216fixed\u5b9a\u4f4d\u662f\u5fc5\u987b\u7684 *\/<\/span>\n  clip: rect(30px 200px 200px 20px); <span style=\"color:green;\">\/* \u6216\"auto\" *\/<\/span>\n\n  <span style=\"color:green;\">\/* \u5982\u4eca\u7684\u526a\u88c1 (\u65e0\u9700\u5b9a\u4f4d\u5c5e\u6027) *\/<\/span>\n  clip-path: inset(30px 200px 200px 20px); <span style=\"color:green;\">\/* \u6216\"none\" *\/<\/span>\n} <\/pre>\n<\/div>\n<p>\u6309\u7167\u5e38\u8bc6\u7406\u89e3\uff0c\u56db\u4e2a\u65b9\u4f4d\u503c\u542b\u4e49\u5e94\u8be5\u548c\u4f20\u7edf<code>clip: rect()<\/code>\u662f\u4e00\u6a21\u4e00\u6837\u6ef4\uff08\u53c2\u8003\u4e0b\u56fe\u793a\u610f\uff0c\u82e5\u8fd8\u4e0d\u5f00\u7a8d\uff0c\u53bb<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/2011\/04\/css-clip-rect\/\">CSS clip<\/a>\u4e00\u6587\u770b\u8be6\u89e3\uff09\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"clip:rect\u503c\u793a\u610f\u4e0ephotoshop\u53c2\u8003\u7ebf\" class=\"mt10\" width=\"300\" height=\"300\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201104\/2011-04-02_000416.png\"><\/p>\n<p>\u4f46\u662f\uff0c\u4f46\u662f\uff0c\u6ce8\u610f\u524d\u65b9\u9ad8\u80fd\uff01\u6839\u636e\u6211\u5728Chrome\u6d4f\u89c8\u5668\u4e0b\u7684\u6d4b\u8bd5\uff08\u76ee\u524d\u4e3a\u6570\u4e0d\u591a\u652f\u6301<code>clip-path:inset()<\/code>\u7684\u6d4f\u89c8\u5668\uff09\u4e0b\u7684\u6d4b\u8bd5\uff0c<code>clip-path:inset()<\/code>4\u4e2a\u503c\u7684\u542b\u4e49\u4e0e\u4f20\u7edf<code>clip: rect()<\/code><strong>\u662f\u4e0d\u4e00\u6837\u7684<\/strong>\uff01<\/p>\n<p>\u6216\u8bb8\u662f\u76ee\u524d\u7684Chrome\u8fd8\u4e0d\u662f\u5f88\u89c4\u8303\uff0c\u4f46\u662f\uff0c\u81f3\u5c11\uff0c\u5f53\u4e0b\uff0c\u4e24\u8005\u662f\u6709\u5dee\u522b\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0a\u9762<code>.clip-me {} <\/code>\u5bf9\u5e94CSS\u4ee3\u7801\u5e94\u7528\u5230\u56fe\u7247\u4e0a\uff0c\u5219\u4f1a\u662f\u8fd9\u6837\u5b50\uff0c\u4e00\u4e2a\u526a\u88c1\uff0c\u4e00\u4e2a\u6728\u6709\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-02_232959.png\" width=\"311\" height=\"440\" alt=\"clip\u624d\u8d77\u4f5c\u7528\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u5df2\u77e5\uff0c\u6b64\u59b9\u5b50\u56fe\u7247\u5c3a\u5bf8\u662f<code>256 * 191<\/code>\uff0c\u6b64\u65f6\uff0c\u5982\u679c\u6211\u4eec<code>clip-path:inset()<\/code>\u5982\u4e0b\u8bbe\u7f6e\uff0c\u5219\u7ed3\u679c\u5927\u4e0d\u540c\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.clip-me {\n    clip-path: inset(30px 56px 0 20px);\n}<\/pre>\n<\/div>\n<p>\u5219\u662f\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-02_233205.png\" width=\"289\" height=\"496\" alt=\"clip-path\u6210\u529f\u526a\u88c1\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u4f1a\u770b\u5230\u526a\u88c1\u533a\u57df\u5927\u5c0f\u90fd\u4e00\u6837\u4e86\uff01\u8bf6\uff1f\u6211\u4eec\u4e0d\u7981\u7591\u95ee\uff0c<code>clip-path:inset()<\/code>\u56db\u4e2a\u503c\u7684\u7384\u673a\u5728\u54ea\u91cc\uff1f\u5f88\u7b80\u5355\uff0c\u867d\u7136\u56db\u4e2a\u503c\u4ee3\u8868\u7684\u65b9\u4f4d\u662f\u4e00\u6837\u7684\uff0c\u5206\u522b\u662f\u4e0a\u8fb9\u7f18\u3001\u53f3\u8fb9\u7f18\u3001\u4e0b\u8fb9\u7f18\u548c\u5de6\u8fb9\u7f18\uff1b\u4f46\u662f\uff0c\u503c\u5927\u5c0f\u5bf9\u5e94\u7684\u5219\u662f<strong>\u8ddd\u79bb\u539f\u59cb\u5143\u7d20\u76844\u4e2a\u8fb9\u7684\u8ddd\u79bb<\/strong>\uff08\u4f20\u7edfclip\u662f\u5bf9\u5e94\u201c\u4e0a\/\u5de6\u201d2\u4e2a\u8fb9\u8ddd\u79bb\uff09\u3002\u52a0\u51cf\u793a\u610f\u4e0b\u5c31\u662f\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>\nclip: rect(30px 200px 200px 20px)\n=\nclip-path: inset(30px (256-200)px (191-200)px 20px)\n<\/pre>\n<\/div>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201412\/css-clip-path-inset.html\" target=\"_blank\">CSS clip-path inset\u56fe\u7247\u526a\u88c1\u793a\u610fdemo<\/a><\/p>\n<p>\u4f5c\u4e3a\u65b0\u65f6\u4ee3\u7684\u5ba0\u513f\uff0c\u81ea\u7136<code>inset<\/code>\u4e0d\u80fd\u5c31\u77e9\u5f62\u526a\u88c1\u8fd9\u4e48\u70b9\u82b1\u6837\uff0c\u4f8b\u5982\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.clip-path {\n    -webkit-clip-path: inset(10% round 10% 50% 10% 50%);\n            clip-path: inset(10% round 10% 50% 10% 50%);\n}<\/pre>\n<\/div>\n<p>\u5219\u4f1a\u8ba9\u56fe\u7247\u526a\u88c1\u6210\u8fd9\u6837\u5b50\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-02_233352.jpg\" width=\"214\" height=\"172\" alt=\"clip-path inset\u66f4\u9ad8\u7ea7\u7684\u526a\u88c1\" class=\"alignnone\" \/><\/p>\n<p>\u5176\u4e2d<code>round<\/code>\u5173\u952e\u5b57\u8868\u793a\u5706\u89d2\u4e4b\u610f\u3002\u7136\u540e\u524d\u540e\u4e2a\u652f\u6301\u6700\u591a4\u4e2a\u503c\uff0c\u548c<code>border-radius<\/code>\u7c7b\u4f3c\uff0c4\u4e2a\u503c\u5206\u522b\u5bf9\u5e94\u5de6\u4e0a\u89d2\u53ca\u987a\u65f6\u9488\u65b9\u54113\u4e2a\u89d2\u3002\u524d\u97624\u4e2a\u503c\u5e94\u8be5\u662f\u5916\u5706\u89d2\uff0c\u540e\u97624\u4e2a\u503c\u5e94\u8be5\u8868\u793a\u5185\u5706\u89d2\u3002<\/p>\n<p><strong>2. clip-path\u4e0eSVG clip-path<\/strong><br \/>\n<code>clip-path<\/code>\u9664\u4e86\u4f5c\u4e3a<code>clip<\/code>\u7684\u66ff\u8eab\uff0c\u8fd8\u662fSVG <code>clip-path<\/code>\u5c5e\u6027\u7684\u5ef6\u4f38\u3002\u4e8e\u662f\uff0cSVG\u4e2d\u73a9\u5f97\u6bd4\u8f83\u5f00\u5fc3\u7684\u4e1c\u897fCSS\u4e2d\u4e5f\u540c\u6837\u9002\u7528\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.clip-me { \n  <span style=\"color:green;\">\/* \u526a\u88c1\u8def\u5f84\u6765\u81ea\u5185\u8054SVG &lt;clipPath>\u5143\u7d20 *\/<\/span>\n  clip-path: url(#c1); \n\n  <span style=\"color:green;\">\/* \u8def\u5f84\u6765\u81ea\u5916\u90e8SVG *\/<\/span>\n  clip-path: url(path.svg#c1);\n\n  <span style=\"color:green;\">\/* \u591a\u8fb9\u5f62 *\/<\/span>\n  clip-path: polygon(5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%);\n\n  <span style=\"color:green;\">\/* \u5706 *\/<\/span>\n  clip-path: circle(30px at 35px 35px);\n\n  <span style=\"color:green;\">\/* \u692d\u5706 *\/<\/span>\n  clip-path: ellipse(65px 30px at 125px 40px);\n}<\/pre>\n<\/div>\n<p>\u770b\u4e0a\u53bb\u597dNB, \u4f46\u662f\uff0c\u517c\u5bb9\u6027\u662f\u5f88\u7cdf\u7cd5\u7684\u73b0\u72b6\u3002IE\u6d4f\u89c8\u5668\u5168\u519b\u8986\u6ca1\u3002FireFox\u6d4f\u89c8\u5668\u76ee\u524d(v36)\u4ec5\u652f\u6301<code>url()<\/code>\u89e3\u6790, Chrome\u6d4f\u89c8\u5668\u8981\u9886\u5148\u4e0d\u5c11\uff08\u540c\u6837\u6709iOS Safari 7.1+, Android Browser 4.4+\uff09\uff0c\u4e0d\u4ec5\u652f\u6301\u5168\u90e8\u7684\u56fe\u5f62\u89e3\u6790\uff0c\u8fd8\u652f\u6301\u5185\u8054SVG\u7684<code>url(#foo)<\/code>\u89e3\u6790\uff0c\u4f46\u662f\uff0c\u5916\u90e8SVG\u6587\u4ef6\u7684<code>url()<\/code>\u89e3\u6790\u8fd8\u4e0d\u652f\u6301\u3002\u540c\u65f6\uff0c\u76ee\u524d(v42)\u90e8\u5206\u7279\u6027\u9700\u8981\u6dfb\u52a0<code>-webkit-<\/code>\u79c1\u6709\u524d\u7f00\u7684\uff0c\u5982\u4e0a\u9762\u4ecb\u7ecd\u7684<code>inset<\/code>\u3002<\/p>\n<p>\u540c\u65f6\uff0c\u57fa\u672c\u4e0a\uff0c<code>path<\/code>\u5143\u7d20\u662f\u65e0\u6cd5\u652f\u6301\u7684\uff0c\u4e3b\u8981\u662f\u8bed\u6cd5\u592a\u590d\u6742\uff0c\u65e0\u6cd5\u5728CSS\u4e2d\u4ee5\u7b80\u6613\u89c4\u5219\u4e66\u5199\u3002<\/p>\n<p>\u5f53\u56fe\u5f62\u5143\u7d20\u53d8\u6210CSS <code>clip-path<\/code>\u7684\u5ac1\u8863\u65f6\u5019\uff0c\u8bed\u6cd5\u4f1a\u6709\u4e9b\u53d8\u5316\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.clip-examples {\n  clip-path: rectangle(x, y, width, height, rounded-x, rounded-y)  \n  clip-path: inset-rectangle(from top, from right, from bottom, from left, rounded-x, rounded-y)   <span style=\"color:green;\">\/* \u5e94\u4f7f\u7528inset()\u66ff\u6362\u4e4b~ *\/<\/span>\n  clip-path: polygon(a, bunch, of, points)\n  clip-path: circle(radius at x, y)\n  clip-path: ellipse(radius-x, radius-y at x, y)\n}<\/pre>\n<\/div>\n<p><code>clip-path<\/code>\u5728CSS\u8bed\u6cd5\u4e2d\u6e38\u8d70\u7684\u65f6\u5019\uff0c\u4e5f\u4f20\u627f\u4e86CSS3\u7684\u4e00\u4e9b\u9ad8\u7ea7\u7279\u6027\uff0c\u6bd4\u65b9\u8bf4<code>transition<\/code>\u8fc7\u6e21\u548c<code>animation<\/code>\u52a8\u753b\uff0c\u4f8b\u5982\u4e0b\u9762\u8fd9\u4e2a\u6548\u679c\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201412\/clip-path-ani-s.gif\" width=\"266\" height=\"200\" alt=\"hover\u77e9\u5f62\u53d8\u6210\u5706\u7684\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>\u522b\u5c0f\u770b\u4e0a\u9762\u7684\u6548\u679c\uff0c\u5982\u679c\u662f\u7eaf\u7cb9\u7684CSS\u6280\u672f\uff0c\u8fd8\u771f\u5b9e\u73b0\u4e0d\u4e86\u8fd9\u822c\u6548\u679c\uff0c\u56e0\u4e3a\u603b\u4f1a\u6709\u4e9b\u4f4d\u79fb\uff08\u4e0d\u670d\u4f60\u53ef\u4ee5\u6311\u6218\uff09\uff0c\u53ea\u80fd\u4f7f\u7528\u8fd9\u79cd\u526a\u88c1\u6216\u8005<code>mask<\/code>\u906e\u7f69\u5b9e\u73b0\u3002<\/p>\n<p>\u76f8\u5173CSS\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.clip-path {\n    transition: 0.4s cubic-bezier(1, -1, 0, 2);\n    -webkit-clip-path: circle(180px at 128px 95px);\n    clip-path: circle(180px at 128px 95px);\n}\n.clip-path:hover {\n    -webkit-clip-path: circle(95px at 128px 95px);\n    clip-path: circle(95px at 128px 95px);\n}<\/pre>\n<\/div>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" href=\"http:\/\/www.zhangxinxu.com\/study\/201412\/css-clip-path-rect-radius-transition.html\" target=\"_blank\">CSS clip-path\u4ece\u65b9\u5f62\u90fd\u5706\u5f62\u52a8\u753b\u6548\u679c\u793a\u610fdemo<\/a> <\/p>\n<h3>\u56db\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>\u76f8\u5173\u5185\u5bb9\u5f88\u591a\u7684\uff0c\u7bc7\u5e45\u6709\u9650\uff0c\u5bb9\u4e0d\u5c0f\u90a3\u4e48\u591a\u3002\u65e8\u5728\u5c55\u793a\u4e00\u4e9b\u57fa\u672c\u5e94\u7528\u3002\u5f53\u4e0bCSS <code>clip-path<\/code>\u8fd8\u5728\u5feb\u901f\u53d1\u5c55\u4e4b\u4e2d\uff0c\u4f46\u662f\uff0c\u6709\u4e9b\u6548\u679c\u8fd8\u771f\u5f97<code>clip-path<\/code>\u6765\u534f\u52a9\u5b9e\u73b0\uff0c\u8fd9\u4f7f\u5f97\u5373\u4f7f\u73b0\u5728\u7684\u517c\u5bb9\u60c5\u51b5\u4e0d\u4f73\u3001\u8fd8\u6709N\u591a\u9650\u5236\u4e0e\u4e0d\u652f\u6301\uff0c\u4f46\u4ecd\u65e0\u6cd5\u963b\u6321<code>clip-path<\/code>\u5728\u4e2a\u4eba\u6216\u5185\u90e8\u9879\u76ee\u4e2d\u5189\u5189\u5347\u8d77\u3002<\/p>\n<p>\u6211\u53ea\u60f3\u8bf4\uff0c\u6f5c\u529b\u5de8\u5927\u3002\u60f3\u60f3\u5f53\u5e74CSS\u5bf9HTML\u53d1\u5c55\u4ee5\u53ca\u6574\u4e2aweb\u53d1\u5c55\u8d21\u732e\uff1b\u5728\u770b\u770b\u73b0\u5728CSS\u5bf9SVG\u53d1\u5c55\u4ee5\u53ca\u6574\u4e2aweb\u53d1\u5c55\u7684\u8d21\u732e\u3002\u8bf4\u4e0d\u51c6\u5c31\u4f1a\u6380\u8d77\u53c8\u4e00\u4e2a\u53d1\u5c55\u6d6a\u6f6e\uff0c\u4f1a\u8fce\u6765\u4f53\u73b0\u66f4\u4f73\u7684\u8bf8\u591aweb\u7ad9\u70b9\u3002<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u7ea0\u9519\uff0c\u6b22\u8fce\u4ea4\u6d41\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/49.gif\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u6709\u5c11\u90e8\u5206\u5185\u5bb9\u53c2\u8003\u81ea\uff1a<\/p>\n<ul>\n<li><a href=\"http:\/\/tutorials.jenkov.com\/svg\/clip-path.html\" target=\"_blank\">SVG Clip Path<\/a><\/li>\n<li><a href=\"http:\/\/css-tricks.com\/clipping-masking-css\/\" target=\"_blank\">Clipping and Masking in CSS<\/a><\/li>\n<\/ul>\n<p>\u4ee5\u4e0a~<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=4501\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=4501<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS3\u65b0\u589e\u5c5e\u6027\u9664\u4e86\u6211\u4eec\u73b0\u5728\u7528\u7684\u6bd4\u8f83\u591a\u7684<code>border-radius<\/code>, <code>box-shadow<\/code>, <code>gradient<\/code>, <code>...<\/code>\u4e4b\u7c7b\uff0c\u8fd8\u6709\u5f88\u91cd\u8981\u7684\u4e00\u4e2a\u5206\u652f\uff1a<strong>SVG\u5c5e\u6027\u5bb6\u65cf\uff01<\/strong><\/p>\n<p>\u6240\u8c13\u300cSVG\u5c5e\u6027\u5bb6\u65cf\u300d\u662f\u6307\u539f\u672cSVG\u7684\u6807\u7b7e\u5c5e\u6027\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528CSS\u8bbe\u7f6e\u3002\u672c\u6587\u7684<code>clip-path<\/code>\u5c31\u662f\u5176\u4e2d\u4e00\u4e2a\u5c5e\u6027\uff0c\u53ef\u4ee5\u6e38\u8d70\u4e8eSVG\u5c5e\u6027\u548cCSS\u5c5e\u6027\u4e4b\u524d\u3002\u672c\u6587\u4e2d\u7b49\u7bc7\u5e45\uff0c\u4e2d\u7b49\u96be\u5ea6\uff0c\u4e30\u5bcc\u7684\u6e90\u4ee3\u7801\u5c55\u793a\uff0c\u4e30\u5bcc\u7684demo\u9875\u9762\uff0c\u4e30\u5bcc\u7684\u622a\u56fe\uff0c\u8fd8\u6709\u5fc5\u8981\u7684gif\u6f14\u793a\uff0c\u603b\u4e4b\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01<\/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,177,642,226,104],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/4501"}],"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=4501"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/4501\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=4501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=4501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=4501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}