{"id":9116,"date":"2019-12-07T23:41:52","date_gmt":"2019-12-07T15:41:52","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9116"},"modified":"2020-05-21T23:35:29","modified_gmt":"2020-05-21T15:35:29","slug":"css-repeat","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/12\/css-repeat\/","title":{"rendered":"CSS repeat()\u51fd\u6570\u8be6\u7ec6\u4ecb\u7ecd"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9116\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9116<\/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\/201912-css-repeat.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/repeat-cover-cut.png\" width=\"402\" height=\"258\" class=\"alignright clip size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u524d\u8a00\u4ee5\u53ca\u517c\u5bb9\u6027<\/h3>\n<p>\u524d\u6587\u8bb2\u4e86<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/11\/css-grid-minmax\/\">CSS minmax()\u51fd\u6570<\/a>\uff0c\u73b0\u5728\u8d81\u70ed\u6253\u94c1\uff0c\u4ecb\u7ecd\u4e0bCSS <code>repeat()<\/code>\u51fd\u6570\u3002<\/p>\n<p><code>repeat()<\/code>\u51fd\u6570\u8981\u60f3\u7406\u89e3\u900f\u5f7b\uff0c\u719f\u7ec3\u638c\u63e1\uff0c\u8981\u6bd4<code>minmax()<\/code>\u51fd\u6570\u65f6\u95f4\u591a\u591a\u4e86\u3002<\/p>\n<p>\u8be5\u5982\u4f55\u8bb2\u624d\u80fd\u8ba9\u5927\u5bb6\u66f4\u5bb9\u6613\u7406\u89e3\u5462\uff1f\u7422\u78e8\u4e86\u4e0b\uff0c\u53ef\u4ee5\u4ece\u5b9e\u4f8b\u5165\u624b\uff0c\u4e00\u6b65\u4e00\u6b65\u3002<\/p>\n<p>\u5728\u5c55\u5f00\u4e00\u4e2a\u4e00\u4e2a\u5b9e\u4f8b\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u770b\u4e0b\u8fd9\u4e2a\u51fd\u6570\u7684\u517c\u5bb9\u6027\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>CSS <a href=\"https:\/\/caniuse.com\/#feat=mdn-css_properties_grid-template-rows_repeat\" rel=\"noopener\" target=\"_blank\">repeat()\u51fd\u6570\u517c\u5bb9\u6027<\/a>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-07_182205.png\" width=\"642\" height=\"327\" alt=\"CSS repeat\u51fd\u6570\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>Edge 16+\u652f\u6301\uff0c\u7136\u540eFirefox\u6d4f\u89c8\u5668\u90a3\u91cc\u6709\u4e2a\u4e0a\u6807<sup>\u2462<\/sup>\u8868\u793aFirefox\u6d4f\u89c8\u5668\u6682\u65f6\u53ea\u652f\u6301\u5217\u5c5e\u6027\u7684<code>repeat()<\/code>\u51fd\u6570\u3002\u4e3b\u8981\u4f60\u7684\u9879\u76ee\u4e0d\u662f\u9700\u8981\u517c\u5bb9\u975e\u5e38\u8001\u7684\u624b\u673a\uff0c\u79fb\u52a8\u7aef\u662f\u53ef\u4ee5\u653e\u5fc3\u4f7f\u7528\u7684\u3002<\/p>\n<h3>\u4e8c\u3001\u901a\u8fc7\u5b9e\u4f8b\u4ecb\u7ecdCSS repeat()\u51fd\u6570<\/h3>\n<p>CSS <code>repeat()<\/code>\u51fd\u6570\u53ea\u80fd\u4f5c\u7528\u5728<code>grid-template-columns<\/code>\u548c<code>grid-template-rows<\/code>\u8fd9\u4e24\u4e2aCSS\u5c5e\u6027\u4e0a\uff0c\u7531\u4e8e\u76ee\u524dFirefox\u6d4f\u89c8\u5668\u53ea\u652f\u6301\u5728<code>grid-template-columns<\/code>\u5c5e\u6027\u4e0a\u4f7f\u7528<code>repeat()<\/code>\u51fd\u6570\uff0c\u6240\u4ee5\u672c\u6587\u63a5\u4e0b\u6765\u6240\u6709\u6848\u4f8b\u90fd\u53ea\u663e\u793a\u5217\uff0c\u4e5f\u5c31\u662f\u5bbd\u5ea6\u7684\u8bbe\u7f6e\u3002<\/p>\n<h4>1. repeat()\u51fd\u6570\u4f5c\u7528<\/h4>\n<p>\u5148\u770b\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: 40px auto 60px;\r\n}<\/pre>\n<p>\u8868\u793a\u6211\u4eec\u7684\u5e03\u5c40\u5206\u4e3a\u4e09\u5217\uff0c\u6bcf\u5217\u7684\u5bbd\u5ea6\u5206\u522b\u662f<code>40px<\/code>\uff0c<code>auto<\/code>\uff0c\u4ee5\u53ca<code>60px<\/code>\u3002<\/p>\n<p>\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u518d\u770b\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: 40px auto 60px 40px auto 60px;\r\n}<\/pre>\n<p>\u8868\u793a\u6211\u4eec\u7684\u5e03\u5c40\u5206\u4e3a\u516d\u5217\uff0c\u6bcf\u5217\u7684\u5bbd\u5ea6\u5206\u522b\u662f<code>40px<\/code>\uff0c<code>auto<\/code>\uff0c<code>60px<\/code>\uff0c<code>40px<\/code>\uff0c<code>auto<\/code>\uff0c<code>60px<\/code>\u3002<\/p>\n<p>\u597d\u50cf\u4e5f\u6ca1\u4ec0\u4e48\u95ee\u9898\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u5047\u8bbe\u6211\u4eec\u7684\u5e03\u5c40\u662f12\u5217\u7684\uff0c\u8bf7\u95ee\uff0cCSS\u4ee3\u7801\u4f1a\u662f\u600e\u6837\u7684\uff1f<\/p>\n<p>\u5982\u679c\u6309\u7167\u4e0a\u9762\u5199\u6cd5\uff0c\u662f\u4e0d\u662f\u5e94\u8be5\u5199\u6210\u4e0b\u9762\u8fd9\u6837\uff1f<\/p>\n<pre>.container {\r\n    grid-template-columns: 40px auto 60px 40px auto 60px 40px auto 60px 40px auto 60px;\r\n}<\/pre>\n<p>\u54c7\uff0c\u5c31\u50cf\u8001\u592a\u592a\u88f9\u811a\u5e03\u2014\u2014\u53c8\u81ed\u53c8\u957f\u3002<\/p>\n<p>\u4ee3\u7801\u91cf\u591a\uff0c\u770b\u5f97\u773c\u82b1\uff0c\u8fd8\u4e0d\u597d\u7406\u89e3\uff0c\u7ef4\u62a4\u8d77\u6765\u4e5f\u4e0d\u65b9\u4fbf\u3002<\/p>\n<p>\u6b64\u65f6\uff0c<code>repeat()<\/code>\u7684\u4ef7\u503c\u5c31\u4f53\u73b0\u4e86\uff0c\u4ec0\u4e48\uff0c12\u5217\uff1f\u5c0f\u83dc\u4e00\u789f\u3002\u8bf7\u770b\u8868\u6f14\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(4, 40px auto 60px);\r\n}<\/pre>\n<p>\u975e\u5e38\u597d\u7406\u89e3\uff0c\u91cd\u590d4\u6b21\uff0c\u6bcf\u6b21\u7684\u91cd\u590d\u5355\u5143\u662f<code>40px auto 60px<\/code>\u8fd93\u4e2a\u5c3a\u5bf8\u3002<\/p>\n<p>\u4e8e\u662f\u5c31\u6709\u5982\u4e0bGIF\u6240\u793a\u7684\u6548\u679c\uff08\u70b9\u51fb\u64ad\u653e\uff0c112K\uff09\uff0c\u662f\u6211<span class=\"hidden\" hidden>\u5f20\u946b\u65ed<\/span>\u6700\u7231\u7684\u6df1\u5929\u84dd\u8272\u54e6\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-base.png\" width=\"702\" height=\"139\" alt=\"12\u680frepeat\u8bbe\u7f6e\u6548\u679c\" class=\"alignnone size-medium\" onclick=\"this.src=this.src.replace('.png', '-s.gif')\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201912\/css-repeat-basic.php\" rel=\"noopener\" target=\"_blank\">CSS repeat()\u51fd\u6570\u57fa\u672c\u4f7f\u7528demo<\/a><\/p>\n<h4>2. repeat()\u51fd\u6570\u53ef\u4ee5\u540c\u65f6\u591a\u4e2a<\/h4>\n<p>\u4f8b\u5982\uff0c\u524d\u97623\u5217\u5bbd\u5ea6\u90fd\u662f<code>40px<\/code>\uff0c\u7d27\u8ddf\u77403\u5217\u5bbd\u5ea6\u662f<code>60px<\/code>\uff0c\u5269\u4e0b1\u5217\u5bbd\u5ea6<code>auto<\/code>\uff0c\u5219\u53ef\u4ee5\u8fd9\u4e48\u8bbe\u7f6e\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(3, 40px) repeat(3, 60px) auto;\r\n}<\/pre>\n<p>\u914d\u4e0a\u6211\u6700\u7231\u7684\u6df1\u5929\u7a7a\u84dd\uff0c\u6548\u679c\u5982\u4e0bGIF\u622a\u5c4f\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-multiple.gif\" width=\"606\" height=\"139\" alt=\"\u591a\u4e2arepeat\u51fd\u6570\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201912\/css-repeat-multiple-demo.php\" rel=\"noopener\" target=\"_blank\">\u591a\u4e2arepeat()\u51fd\u6570\u540c\u65f6\u4f7f\u7528demo<\/a><\/p>\n<h4>3. repeat()\u51fd\u6570\u652f\u6301\u5bf9\u7f51\u683c\u7ebf\u547d\u540d<\/h4>\n<p>\u5982\u679c\u7f51\u683c\u7ebf\u7684\u547d\u540d\u4e5f\u662f\u91cd\u590d\u6709\u89c4\u5f8b\u7684\uff0c\u5219\u4e5f\u53ef\u4ee5\u7528\u5728<code>repeat()<\/code>\u51fd\u6570\u4e2d\uff0c<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(3, [col-start] 1fr [col-end]) auto;\r\n}<\/pre>\n<p>\u5176\u4e2d\uff0c<code>[col-start]<\/code>\u548c<code>[col-end]<\/code>\u53ea\u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u547d\u540d\uff0c\u6ca1\u6709\u4ec0\u4e48\u7279\u6b8a\u7684\u542b\u4e49\uff0c\u5173\u952e\u662f<code>[]<\/code>\uff0c\u81f3\u4e8e\u91cc\u9762\u5199\u7684\u5185\u5bb9\uff0c\u5176\u5b9e\u53ea\u8981\u5927\u5bb6\u770b\u5f97\u61c2\u5c31\u884c\uff0c\u8fd9\u91cc\uff0c\u76f4\u63a5<code>repeat(3, [\u5217\u5f00\u59cb] 1fr [\u5217\u7ed3\u675f])<\/code>\u4e5f\u662f\u4e00\u6837\u7684\u6548\u679c\u3002<\/p>\n<p>\u7f51\u683c\u7ebf\u547d\u540d\u4e3b\u8981\u7ed9Grid\u5e03\u5c40\u4e2d\u7684\u5b50\u9879\u4f7f\u7528\u7684\uff0c\u5177\u4f53\u53ef\u4ee5\u53c2\u89c1\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/11\/display-grid-css-css3\/\">\u5199\u7ed9\u81ea\u5df1\u770b\u7684display: grid\u5e03\u5c40\u6559\u7a0b<\/a>\u201d\u4e00\u6587\u3002<\/p>\n<h3>\u4e09\u3001\u5176\u4ed6\u5173\u952e\u5b57\u548c\u51fd\u6570<\/h3>\n<p>\u4e0a\u9762\u7684\u6848\u4f8b\u4e2d\uff0c<code>repeat()<\/code>\u51fd\u6570\u53ea\u6f14\u793a\u4e86\u6570\u503c\u7c7b\u578b\u548c<code>auto<\/code>\u5173\u952e\u5b57\u7684\u6548\u679c\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cCSS <code>repeat()<\/code>\u51fd\u6570\u8fd8\u652f\u6301\u5176\u4ed6\u591a\u4e2a\u5173\u952e\u5b57\u548c\u51fd\u6570\u3002<\/p>\n<h4>1. min-content\/max-content<\/h4>\n<p><code>min-content<\/code>\u548c<code>max-content<\/code>\u5c3a\u5bf8\u662f\u6839\u636e\u5185\u5bb9\u6765\u7684\uff0c<code>min-content<\/code>\u662f\u6700\u5c0f\u5185\u5bb9\u5c3a\u5bf8\uff0c\u4e2d\u6587\u7684\u6700\u5c0f\u5185\u5bb9\u5355\u4f4d\u662f\u4e00\u4e2a\u6c49\u5b57\uff0c\u82f1\u6587\u7684\u6700\u5c0f\u5185\u5bb9\u5355\u4f4d\u662f\u5355\u8bcd\uff0c\u56e0\u6b64<code>min-content<\/code>\u6700\u7ec8\u5bbd\u5ea6\u662f\u6240\u6709\u8fd9\u4e9b\u6700\u5c0f\u5185\u5bb9\u5355\u5143\u6700\u957f\u7684\u90a3\u4e2a\u5355\u5143\u5bbd\u5ea6\uff1b<code>max-content<\/code>\u662f\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u6587\u672c\u5185\u5bb9\u4e0d\u6362\u884c\u65f6\u5019\u7684\u5bbd\u5ea6\u3002\u8be6\u7ec6\u77e5\u8bc6\u53ef\u4ee5\u53c2\u8003<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=5392\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u6848\u4f8b\u770b\u770b<code>min-content<\/code>\/<code>max-content<\/code>\u5728Grid\u5e03\u5c40\u4e2d\u7684\u6548\u679c\uff0cCSS\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(2, min-content auto max-content) auto;\r\n}<\/pre>\n<p>\u5982\u4e0bGIF\u5f55\u5c4f\u56fe\u7247\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-mix-max-content-s.gif\" width=\"605\" height=\"162\" alt=\"min-content\u548cmax-content\u5728repeat\u51fd\u6570\u4e2d\u6548\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<p><code>min-content<\/code>\u6240\u5728\u5217\u7684\u5bbd\u5ea6\u5c31\u662f\u5355\u8bcd<code>content<\/code>\u7684\u5bbd\u5ea6\uff1b<code>max-content<\/code>\u6240\u5728\u5217\u7684\u5bbd\u5ea6\u5c31\u662f\u6574\u4e2a\u8bed\u53e5\u4e0d\u6362\u884c\u65f6\u5019\u7684\u5bbd\u5ea6\u3002<\/p>\n<p><code>min-content<\/code>\u548c<code>max-content<\/code>\u5728\u5b9e\u9645\u5f00\u53d1\u7684\u65f6\u5019\u662f\u4e0d\u4f1a\u76f8\u5bf9\u4e8e\u5b57\u7b26\u8fdb\u884c\u5c3a\u5bf8\u8bbe\u5b9a\u7684\uff0c\u800c\u662f\u76f8\u5bf9\u4e8e\u56fe\u7247\u6216\u8005\u5185\u8054\u6027\u8d28\u7684\u5bb9\u5668\u5143\u7d20\uff0c\u6bd4\u65b9\u8bf4\u5bb9\u5668\u5bbd\u5ea6\u4e0d\u786e\u5b9a\u540c\u65f6\u4e00\u884c\u6700\u591a\u663e\u793a\u4e00\u4e2a\u5bb9\u5668\uff08<code>min-content<\/code>\uff09\uff0c\u6216\u8005\u6240\u6709\u5143\u7d20\u5728\u4e00\u884c\u663e\u793a\uff08<code>max-content<\/code>\uff09\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201912\/css-repeat-min-max-content-demo.php\" rel=\"noopener\" target=\"_blank\">repeat(min-content, max-content)\u793a\u610fdemo<\/a><\/p>\n<h4>2. minmax()\u51fd\u6570<\/h4>\n<p><code>minmax(min, max)<\/code>\u51fd\u6570\u8868\u793a\u5f53\u524d\u8fd9\u4e2a\u683c\u5b50\u7684\u5c3a\u5bf8\u8303\u56f4\u5728<code>min<\/code>\u5230<code>max<\/code>\u4e4b\u95f4\u3002<\/p>\n<p>\u4f8b\u5982\uff1a <\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(2, minmax(min-content, max-content) 40px) auto;\r\n}<\/pre>\n<p>\u6548\u679c\u5982\u4e0bGIF\uff0c112K\uff0c\u70b9\u51fb\u64ad\u653e\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-mixmax.png\" width=\"636\" height=\"182\" alt=\"minmax\u793a\u610f\u6548\u679c\u56fe\" class=\"alignnone size-medium\" onclick=\"this.src=this.src.replace('.png', '.gif')\" \/><\/p>\n<p>\u7b2c1\u5217\u548c\u7b2c3\u5217\u7684\u5bbd\u5ea6\u6700\u5c0f\u662f<code>min-content<\/code>\u5bf9\u5e94\u7684\u5bbd\u5ea6\uff0c\u6700\u5927\u662f<code>max-content<\/code>\u5bf9\u5e94\u7684\u5bbd\u5ea6\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201912\/css-repeat-minmax-demo.php\" rel=\"noopener\" target=\"_blank\">CSS repeat()\u51fd\u6570\u4e2d\u4f7f\u7528minmax() demo<\/a><\/p>\n<p>\u5173\u4e8e<code>minmax()<\/code>\u51fd\u6570\u66f4\u591a\u77e5\u8bc6\u4e0e\u7ec6\u8282\uff0c\u8bf7\u53c2\u8003\u4e0a\u4e00\u7bc7\u6587\u7ae0\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/11\/css-grid-minmax\/\">CSS minmax()\u51fd\u6570\u7b80\u4ecb<\/a>\u201d\u3002<\/p>\n<h4>2. fit-content()\u51fd\u6570<\/h4>\n<p><code>fit-content()<\/code>\u51fd\u6570\u662f\u5e72\u4ec0\u4e48\u7528\u7684\u5462\uff1f<\/p>\n<p>\u4e00\u8a00\u4ee5\u853d\u4e4b\uff0c\u5c3a\u5bf8\u9002\u5e94\u4e8e\u5185\u5bb9\uff0c\u4f46\u4e0d\u8d85\u8fc7\u8bbe\u5b9a\u7684\u5c3a\u5bf8\u3002<\/p>\n<p>\u5e95\u5c42\u8ba1\u7b97\u516c\u5f0f\u5982\u4e0b\uff0c\u6e90\u81ea<a href=\"https:\/\/drafts.csswg.org\/css-grid\/#valdef-grid-template-columns-fit-content\" rel=\"noopener\" target=\"_blank\">\u89c4\u8303\u6587\u6863<\/a>\uff08MDN\u4e0a<a href=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-08_220415.png\" rel=\"noopener\" target=\"_blank\">\u663e\u793a\u7684\u7684\u662f\u9519\u8bef\u7684<\/a>\uff09\uff1a<\/p>\n<pre><del datetime=\"2020-05-21T14:22:33+00:00\">min(minimum, max(limit, max-content))<\/del><\/pre>\n<p><code>minimum<\/code>\u5e76\u4e0d\u5177\u4f53\u6307\u4ee3\u67d0\u4e00\u4e2a\u5bf9\u5e94\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u4e0d\u7b49\u4e8e<code>min-content<\/code>\u4e5f\u4e0d\u7b49\u4e8e<code>auto<\/code>\u3002\u7a76\u7adf\u662f\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u7ecf\u8fc7\u6211\u7684\u7814\u7a76\uff0c\u5565\u90fd\u4e0d\u662f\uff01\u6216\u8005\u8bf4\uff0c\u65e0\u8bba\u662fW3C\u5b98\u65b9\u7684\u516c\u5f0f\u8fd8\u662fMDN\u4e0a\u7684\u516c\u5f0f\u90fd\u662f\u4f1a\u6709\u7406\u89e3\u969c\u788d\u7684\u3002<\/p>\n<p><strong>\u66f4\u65b0\u4e8e2020-05-21<\/strong><br \/>\n<code>minimum<\/code>\u6307\u7684\u662f\u5c3a\u5bf8\u4e0b\u9650\uff0c\u901a\u5e38\u7531\u6700\u5c0f\u5185\u5bb9\u5c3a\u5bf8\u51b3\u5b9a\uff0c\u5982\u679c<code>min-width<\/code>\/<code>min-height<\/code>\u5c3a\u5bf8\u6bd4\u6700\u5c0f\u5185\u5bb9\u5c3a\u5bf8\u5927\uff0c\u5219\u5c3a\u5bf8\u4e0b\u9650\u7531<code>min-width<\/code>\/<code>min-height<\/code>\u51b3\u5b9a\u3002<\/p>\n<p>\u5e95\u5c42\u8ba1\u7b97\u516c\u5f0f\u662f\uff1a<\/p>\n<pre>max(minimum, min(limit, max-content))<\/pre>\n<p><span class=\"s\">&#8212;&#8212;&#8212;- \u66f4\u65b0 end &#8212;&#8212;&#8211;<\/span><\/p>\n<p>\u5927\u5bb6\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u516c\u5f0f\u8fdb\u884c\u8ba1\u7b97\u5427\uff1a<\/p>\n<pre>fit-content(limit) = min(min(auto, limit), min(auto, max-content))<\/pre>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li><code>max-content<\/code>\u5c31\u662f\u6307<code>max-content<\/code>\u5bf9\u5e94\u7684\u5c3a\u5bf8\uff0c\u800c<code>auto<\/code>\u5c31\u662f\u6307<code>auto<\/code>\u5173\u952e\u5b57\u5bf9\u5e94\u7684\u5c3a\u5bf8\u3002<\/li>\n<li><code>min()<\/code>\u5c31\u662fJS\u4e2d<code>Math.min()<\/code>\u7684\u610f\u601d\uff0c\u53d6\u5c0f\u503c\u3002<\/li>\n<\/ul>\n<p>\u53ea\u770b\u516c\u5f0f\u4f1a\u6709\u70b9\u61f5\uff0c\u4e0d\u6025\uff0c\u5b9e\u4f8b\u8bf4\u8bdd\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(2, fit-content(100px) 40px) auto;\r\n}<\/pre>\n<p>\u6548\u679c\u5982\u4e0b\uff0c\u4f9d\u7136\u662f\u6211\u6700\u7231\u7684\u6df1\u5929\u84dd\u8272\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-fit-content.gif\" width=\"415\" height=\"286\" alt=\"fit-content\u6548\u679cGIF\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5176\u4e2d\uff0c\u7b2c1\u5217\u548c\u7b2c3\u5217\u5e94\u7528\u4e86<code>fit-content(100px)<\/code>\u3002<\/p>\n<p>\u542b\u4e49\u5206\u522b\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u7b2c1\u5217<\/strong><br \/>\n3\u4e2a\u4e2d\u6587\uff0c<code>min-content<\/code>\u5bbd\u5ea6\u4e3a1em\uff0c14px\uff1b<code>max-content<\/code>\u5bbd\u5ea6\u4e3a3em\uff0c42px\u3002<\/p>\n<p>\u521d\u59cb\u72b6\u6001\u4e0b\uff0c<code>auto<\/code>\u5173\u952e\u5b57\u5e94\u8be5\u663e\u793a\u7684\u5bbd\u5ea6\u8fdc\u5927\u4e8e<code>max-content<\/code>\uff0c\u90a3\u4e48<code>auto<\/code>\u5c31\u7528<code>666px<\/code>\u4ee3\u66ff\u5427\u3002\u5957\u7528\u516c\u5f0f\u5c31\u662f\uff1a<\/p>\n<pre>fit-content(100px) = min(min(666, 100), min(666, 42)) = 42px\r\n<span style=\"color:green;\">\/\/ \u6700\u5927max-content\u5c3a\u5bf8<\/span><\/pre>\n<p>\u968f\u7740\u5bb9\u5668\u5bbd\u5ea6\u53d8\u5c0f\uff0c<code>auto<\/code>\u5173\u952e\u5b57\u5bf9\u5e94\u7684\u5bbd\u5ea6\u4e5f\u8d8a\u6765\u8d8a\u5c0f\uff0c\u53ef\u4ee5\u4e00\u76f4\u5c0f\u5230<code>min-content<\/code>\u5bbd\u5ea6\uff0c\u4e5f\u5c31\u662f14px\uff0c\u6b64\u65f6\u8c03\u7528\u516c\u5f0f\u5c31\u662f\uff1a<\/p>\n<pre>fit-content(100px) = min(min(14, 100), min(14, 42)) = 14px\r\n<span style=\"color:green;\">\/\/ \u5c0f\u5230min-content\u5c3a\u5bf8<\/span><\/pre>\n<\/li>\n<li><strong>\u7b2c3\u5217<\/strong><br \/>\n\u8fd9\u4e00\u5217\u7684\u4e2d\u6587\u5b57\u7b26\u7279\u522b\u7684\u591a\uff0c<code>max-content<\/code>\u8fdc\u8fdc\u5927\u4e8e<code>100px<\/code>\uff0c\u6211\u4eec\u4e0d\u59a8\u7528\u4e00\u4e2a<code>666px<\/code>\u4ee3\u66ff\u3002<\/p>\n<p>\u521d\u59cb\u72b6\u6001\u4e0b\uff0c<code>auto<\/code>\u5173\u952e\u5b57\u5bf9\u5e94\u7684\u5bbd\u5ea6\u662f\u5927\u4e8e100px\u7684\uff0c\u4e0d\u59a8\u7528<code>233px<\/code>\u4ee3\u66ff\uff0c\u56e0\u6b64\uff0c\u6b64\u65f6<code>fit-content(100px)<\/code>\u7684\u5c3a\u5bf8\u8ba1\u7b97\u503c\u5c31\u662f\u9650\u5b9a\u7684<code>100px<\/code>\u5927\u5c0f\uff1a<\/p>\n<pre>fit-content(100px) = min(min(233, 100), min(233, 666)) = 100px\r\n<span style=\"color:green;\">\/\/ \u9650\u5b9a\u7684\u5c3a\u5bf8<\/span><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-08_213036.png\" width=\"410\" height=\"296\" alt=\"100px\u5927\u5c0f\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u968f\u7740\u5bb9\u5668\u5bbd\u5ea6\u53d8\u5c0f\uff0c<code>auto<\/code>\u5173\u952e\u5b57\u5bf9\u5e94\u7684\u5bbd\u5ea6\u4e5f\u8d8a\u6765\u8d8a\u5c0f\uff0c\u53ef\u4ee5\u4e00\u76f4\u5c0f\u5230<code>min-content<\/code>\u5bbd\u5ea6\uff0c\u8fd9\u91cc<code>min-content<\/code>\u7684\u5bbd\u5ea6\u503c\u5e94\u8be5\u662f<code>'100px'<\/code>\u8fd95\u4e2a\u5b57\u7b26\u7684\u5bbd\u5ea6\u4e86\uff0c\u6211\u91cf\u4e86\u4e00\u4e0b\uff0c\u5728\u6211\u7684\u7535\u8111\u4e0b\u9762\u662f38\u50cf\u7d20\u3002<\/p>\n<p>\u4e8e\u662f\u516c\u5f0f\u7528\u8d77\u6765\uff1a<\/p>\n<pre>fit-content(100px) = min(min(38, 100), min(38, 666)) = 38px<\/pre>\n<p>\u5f97\u5230\u5bbd\u5ea6\u662f<code>38px<\/code>\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53\u7136\u65e5\u5e38\u5e73\u65f6\u5f00\u53d1\u554a\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u5957\u7528\u516c\u5f0f\u8ba1\u7b97\u5b83\u6700\u7ec8\u663e\u793a\u7684\u503c\u3002\u56e0\u4e3a\u516c\u5f0f\u867d\u7136\u590d\u6742\uff0c\u4f46\u6700\u7ec8\u7684\u8868\u73b0\u5f62\u5f0f\u7528\u8bed\u8a00\u63cf\u8ff0\u5c31\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<p><strong>\u201c\u5c3a\u5bf8\u7531\u5185\u5bb9\u51b3\u5b9a\uff0c\u5185\u5bb9\u8d8a\u591a\u5c3a\u5bf8\u8d8a\u5927\uff0c\u4f46\u4e0d\u8d85\u8fc7\u9650\u5b9a\u7684\u5c3a\u5bf8\u3002\u201d<\/strong><\/p>\n<hr>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>fit-content( [ &lt;length&gt; | &lt;percentage&gt; ] )<\/pre>\n<p>\u53ea\u652f\u6301\u957f\u5ea6\u503c\u548c\u767e\u5206\u6bd4\u503c\u3002<\/p>\n<h3>\u56db\u3001\u5982\u679c\u91cd\u590d\u7684\u6570\u91cf\u4e0d\u786e\u5b9a<\/h3>\n<p>\u4ee5\u4e0a\u6240\u6709\u6848\u4f8b\u5c55\u793a\u7684\u90fd\u662f\u6211\u4eec\u77e5\u9053\u5217\u8868\u6570\u76ee\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u6211\u4eec\u4e0d\u77e5\u9053\u5217\u8868\u6570\u76ee\u5177\u4f53\u662f\u591a\u5c11\uff0c\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u8be5\u5982\u4f55\u4f7f\u7528<code>repeat()<\/code>\u51fd\u6570\u5462\uff1f<\/p>\n<p>CSS\u4e2d\u6709\u4e24\u4e2a\u5173\u952e\u5b57\u5c31\u662f\u7528\u5728\u8fd9\u79cd\u573a\u666f\u4e0b\u7684\uff0c\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u5206\u522b\u662f<code>auto-fill<\/code>\u548c<code>auto-fit<\/code>\u3002<\/p>\n<h4>1. auto-fill<\/h4>\n<p>\u6839\u636eGrid\u5e03\u5c40\u4e2d\u6bcf\u4e00\u4e2a\u5b50\u9879\u7684\u5c3a\u5bf8\u81ea\u52a8\u8ba1\u7b97\u9700\u8981\u586b\u5145\u7684\u6570\u91cf\u3002<\/p>\n<p>\u8ba1\u7b97\u89c4\u5219\u662f\uff0c\u5f53\u524d\u5217\u8868\u6570\u91cf\u4e0b\u7684\u603b\u5c3a\u5bf8\u4e0d\u4f1a\u8d85\u51faGrid\u5bb9\u5668\u7684\u6700\u5927\u6b63\u6574\u6570\u503c\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6709\u5982\u4e0bCSS\u4ee3\u7801\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));\r\n}<\/pre>\n<p>\u8868\u793a\u5e03\u5c40\u7a76\u7adf\u6709\u591a\u5c11\u5217\u662f\u4e0d\u786e\u5b9a\u7684\uff0c\u4f46\u662f\u6bcf\u4e00\u5217\u7684\u5bbd\u5ea6\u6700\u5c0f\u662f<code>100px<\/code>\u3002<\/p>\n<p>\u6548\u679c\u5982\u4e0b\uff0c\u9ed8\u8ba4\u5bbd\u5ea6\u5f88\u5bbd\u7684\u60c5\u51b5\u4e0b\uff0c\u6700\u540e\u4f1a\u6709\u533f\u540d\u7684\u683c\u5b50\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-08_234138.png\" width=\"727\" height=\"183\" alt=\"\u9690\u533f\u7684\u683c\u5b50\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u968f\u7740\u5c3a\u5bf8\u53d8\u5c0f\uff0c\u5217\u6570\u4f1a\u8ddf\u7740\u52a8\u6001\u53d8\u5316\uff0c\u540c\u65f6\u5bbd\u5ea6\u81ea\u52a8\u586b\u5145Grid\u5bb9\u5668\uff08\u56e0\u4e3a\u8bbe\u7f6e\u4e86<code>1fr<\/code>\uff09\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-auto-fill.gif\" width=\"681\" height=\"336\" alt=\"\u5f39\u6027\u53d8\u5316\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201912\/css-repeat-auto-fill-demo.php\" rel=\"noopener\" target=\"_blank\">CSS repeat()\u51fd\u6570auto-fill\u81ea\u52a8\u586b\u5145demo<\/a><\/p>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528<code>auto-fill<\/code>\u81ea\u52a8\u586b\u5145\u7684\u65f6\u5019\uff0c<code>repeat()<\/code>\u51fd\u6570\u662f\u4e0d\u80fd\u548cauto\u4e00\u8d77\u4f7f\u7528\u7684\uff0c\u4f8b\u5982\u4e0b\u9762\u8fd9\u79cd\u5199\u6cd5\u662f\u65e0\u6548\u7684\uff1a<\/p>\n<pre style=\"color:#666;\">.container {\r\n    <span style=\"color:#cd0000;\">\/* \u65e0\u6548 *\/<\/span>\r\n    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) auto;\r\n}<\/pre>\n<p>\u4f46\u662f\u53ef\u4ee5\u548c\u957f\u5ea6\u53ea\u548c\u767e\u5206\u6bd4\u503c\u4e00\u8d77\u4f7f\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>.container {\r\n    <span style=\"color:green;\">\/* \u6709\u6548 *\/<\/span>\r\n    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) 20%;\r\n}<\/pre>\n<p>\u8fd9\u6837\uff0c\u6bcf\u4e00\u884c\u6700\u540e\u4e00\u5217\u7684\u5bbd\u5ea6\u90fd\u4f1a\u662f\u5bb9\u5668\u768420%\u5927\u5c0f\uff0c\u622a\u56fe\u793a\u610f\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-08_235122.png\" width=\"242\" height=\"317\" alt=\"\u6700\u540e\u4e00\u521720%\" class=\"alignnone size-medium\" \/><\/p>\n<h4>2. auto-fit<\/h4>\n<p><code>auto-fit<\/code>\u548c<code>auto-fill<\/code>\u7684\u884c\u4e3a\u662f\u76f8\u4f3c\u7684\uff0c\u533a\u522b\u5728\u4e8e<code>auto-fit<\/code>\u4f1a\u628a\u7a7a\u7684\u533f\u540d\u683c\u5b50\u8fdb\u884c\u6298\u53e0\u5408\u5e76\uff0c\u800c\u8fd9\u4e2a\u5408\u5e76\u7684<code>0px<\/code>\u5927\u5c0f\u683c\u5b50\u53ef\u4ee5\u8ba4\u4e3a\u5177\u6709\u5355\u4e2a\u683c\u5b50\u8f68\u9053\u5927\u5c0f\u8c03\u6574\u7684\u529f\u80fd\uff0c\u5bf9\u4e86\uff0c\u5176\u4e24\u4fa7\u7684\u683c\u5b50\u8fc7\u9053\u4e5f\u4f1a\u5408\u5e76\u3002<\/p>\n<p>\u4ec0\u4e48\u610f\u601d\u5462\uff1f<\/p>\n<p>\u5728<code>auto-fill<\/code>\u81ea\u52a8\u586b\u5145\u7684\u65f6\u5019\uff0c\u5982\u679cGrid\u5bb9\u5668\u7684\u5c3a\u5bf8\u7279\u522b\u7684\u5bbd\uff0c\u5219\u6700\u540e\u4f1a\u6709\u4e00\u4e9b\u7a7a\u7684\u683c\u5b50\u5360\u4f4d\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-08_234138.png\" width=\"727\" height=\"183\" alt=\"\u9690\u533f\u7684\u683c\u5b50\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4f46\u662f<code>auto-fit<\/code>\u81ea\u52a8\u9002\u5e94\u7684\u65f6\u5019\uff0c\u5982\u679cGrid\u5bb9\u5668\u7684\u5c3a\u5bf8\u7279\u522b\u7684\u5bbd\uff0c\u5219\u6700\u540e\u4f1a\u6709\u4e00\u4e9b\u7a7a\u7684\u683c\u5b50\u4f1a\u5408\u5e76\u62101\u4e2a\uff0c\u4e14\u5bbd\u5ea6\u662f0\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-09_000143.png\" width=\"721\" height=\"167\" alt=\"auto-fit\u533a\u522b\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e5f\u5c31\u662f<code>auto-fit<\/code>\u573a\u666f\u4e0b\uff0c\u65e0\u8bbaGrid\u5bb9\u5668\u591a\u5bbd\uff0c\u5b50\u9879\u5143\u7d20\u4e00\u5b9a\u662f\u5c3a\u5bf8\u4e00\u5b9a\u662f\u586b\u6ee1\u7684\uff1b\u5f53Grid\u5bb9\u5668\u5c3a\u5bf8\u6ca1\u6709\u5bcc\u4f59\u7684\u65f6\u5019\uff0c\u4e24\u8005\u8868\u73b0\u53c8\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u6548\u679c\u5bf9\u6bd4\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>.container {\r\n    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));\r\n}<\/pre>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/grid-repeat-auto-fit.gif\" width=\"681\" height=\"336\" alt=\"\u5f39\u6027\u53d8\u5316\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201912\/css-repeat-auto-fit-demo.php\" rel=\"noopener\" target=\"_blank\">CSS repeat()\u51fd\u6570auto-fit\u81ea\u52a8\u9002\u5e94demo<\/a> \uff08\u5927\u5c4f\u4e0b\u624d\u80fd\u770b\u51fa\u548cauto-fill\u5dee\u5f02\uff09<\/p>\n<p>\u5b9e\u9645\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u6309\u7167\u6211\u4e2a\u4eba\u7ecf\u9a8c\uff0c\u5efa\u8bae\u4f7f\u7528<code>auto-fit<\/code>\u3002<\/p>\n<h3>\u4e94\u3001\u540e\u8a00\u53ca\u5b9e\u7528\u6027<\/h3>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u7684\u7ec6\u8282\u8981\u6bd4\u6211\u4e00\u5f00\u59cb\u5199\u7684\u65f6\u5019\u4ee5\u4e3a\u7684\u8981\u591a\u5f88\u591a\uff0c\u4ee5\u81f3\u4e8e\u5468\u672b\u4e24\u5929\u5c31\u5199\u4e86\u8fd9\u4e00\u7bc7\u6587\u7ae0\uff0c\u5c0f\u8bf4\u6765\u4e0d\u53ca\u66f4\u65b0\u4e86\u3002<\/p>\n<p>Grid\u5e03\u5c40\u9002\u5408\u65b9\u65b9\u6b63\u6b63\u7eb5\u6a2a\u4ea4\u9519\u7684\u5e03\u5c40\uff0c\u5728IE10\u6d4f\u89c8\u5668\u652f\u6301\u7684\u90a3\u4e00\u7248\u8bed\u6cd5\u4e2d\uff0cGrid\u5e03\u5c40\u7684\u4f18\u52bf\u5176\u5b9e\u5e76\u4e0d\u662f\u5f88\u660e\u663e\uff0c\u5176\u5b9e\u73b0\u7684\u4e1c\u897f\u57fa\u672c\u4e0a\u90fd\u6709\u7c7b\u4f3c\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u6240\u4ee5\uff0c\u5f53\u65f6\u6211\u8868\u793a\u5185\u5fc3\u5f88\u5e73\u9759\uff0c\u6ca1\u6709\u4efb\u4f55\u6ce2\u52a8\u3002<\/p>\n<p>\u4ec0\u4e48\u65f6\u5019\u5f00\u59cb\u89c9\u5f97Grid\u5e03\u5c40\u8fd8\u633a\u5c4c\u7684\u5462\uff1f<\/p>\n<p>\u5c31\u662f\u6d4f\u89c8\u5668\u5f00\u59cb\u7eb7\u7eb7\u652f\u6301<code>repeat()<\/code>\uff0c<code>minmax()<\/code>\uff0c<code>fit-content()<\/code>\u7b49\u51fd\u6570\u548c<code>auto-fill<\/code>\uff0c<code>auto-fit<\/code>\u7b49\u5173\u952e\u5b57\u4e4b\u540e\uff0c\u5176\u5b9e\u73b0\u7684\u5f39\u6027\u5e03\u5c40\u6548\u679c\u662f\u4ee5\u5f80\u6ca1\u6709\u4efb\u4f55CSS\u5c5e\u6027\u80fd\u591f\u5b9e\u73b0\u7684\uff0c\u8ba9Grid\u5e03\u5c40\u7684\u7b49\u7ea7\u63d0\u5347\u4e86\u3002<\/p>\n<p>\u7136\u540e\u81ea\u5df1\u4e5f\u610f\u8bc6\u5230\u4e00\u4e2a\u95ee\u9898\uff0cGrid\u5e03\u5c40\u63d0\u5347\u5e76\u4e0d\u662f\u6211\u4e00\u5f00\u59cb\u4ee5\u4e3a\u7684<code>repeat()<\/code>\u51fd\u6570\uff0c\u66f4\u591a\u7684\u662f<code>repeat()<\/code>\u51fd\u6570\u91cc\u9762\u652f\u6301\u7684\u90a3\u4e9b\u5173\u952e\u5b57\u548c\u51fd\u6570\uff0c\u4ee5\u53ca\u6574\u4e2a\u5168\u65b0\u7684CSS\u4f53\u7cfb\u3002<\/p>\n<p>\u5982\u679c\u5927\u5bb6\u7684\u9879\u76ee\u5bf9\u517c\u5bb9\u6027\u7684\u8981\u6c42\u8fd8\u6ca1\u6709\u90a3\u4e48\u4e25\u683c\uff0c\u4e0d\u59a8\u8bd5\u8bd5\u4f7f\u7528Grid\u5e03\u5c40\u7684\u65b0\u8bed\u6cd5\u65b0\u7279\u6027\u3002<\/p>\n<p>\u7279\u522b\u662f\u90a3\u4e9b\u7eb5\u6a2a\u4ea4\u9519\u7684\u5e03\u5c40\uff08\u89c1\u4e0b\u9762\u9002\u5408\u4f7f\u7528Grid\u5e03\u5c40\u7684\u793a\u610f\uff09\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/2019-12-09_002031.png\" width=\"510\" height=\"261\" alt=\"Grid\u5e03\u5c40\u548cFlex\u5e03\u5c40\u5404\u81ea\u4ee3\u8868\u6848\u4f8b\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u884c\u6587\u4e0d\u6613\uff0c\u505ademo\u4e5f\u4e0d\u6613\uff0cGIF\u5f55\u5c4f\u65b9\u4fbf\u5927\u5bb6\u5b66\u4e60\u7406\u89e3\u66f4\u4e0d\u6613\u3002<\/p>\n<p>\u5982\u679c\u60a8\u89c9\u5f97\u672c\u6587\u5185\u5bb9\u4e0d\u9519\uff0c\u6b22\u8fce\u5fae\u4fe1\u7fa4\u6216\u670b\u53cb\u5708<a href=\"javascript:\" onclick=\"document.querySelector('.bds_weixin').click()\">\u8f6c\u53d1<\/a>\uff0c\u5c31\u662f\u5bf9\u8fd9\u4e9b\u201c\u4e0d\u6613\u201d\u6700\u5927\u7684\u652f\u6301\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f618.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=9116\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9116<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201912\/repeat-cover-cut.png\" width=\"160\" height=\"103\" class=\"alignright size-medium\" alt=\"CSS repeat\u5360\u4f4d\u56fe\" \/><\/p>\n<p>Grid\u5e03\u5c40\u8981\u60f3\u73a9\u7684\u5f88\u6e9c\uff0c<code>repeat()<\/code>\uff0c<code>minmax()<\/code>\uff0c<code>fit-content()<\/code>\u7b49\u51fd\u6570\u548c<code>auto-fill<\/code>\uff0c<code>auto-fit<\/code>\u7b49\u5173\u952e\u5b57\u5c31\u5fc5\u987b\u8981\u975e\u5e38\u4e86\u89e3\u3002\u672c\u6587\u4f1a\u6709\u8be6\u7ec6\u4ecb\u7ecd\uff0cdemo\uff0cGIF\u5f55\u5c4f\u548c\u622a\u56fe\u5e94\u6709\u5c3d\u6709\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u5230\u5927\u5bb6\u7684\u5b66\u4e60\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],"tags":[1525,1526,1059,1514,1057,1058,1527,1283],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9116"}],"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=9116"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9116\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=9116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=9116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=9116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}