{"id":3544,"date":"2024-11-10T17:58:04","date_gmt":"2024-11-10T09:58:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3544\/"},"modified":"2024-11-10T17:58:04","modified_gmt":"2024-11-10T09:58:04","slug":"%e4%bd%bf%e7%94%a8-css-grid-%e5%b8%83%e5%b1%80%e6%97%b6%e5%a6%82%e4%bd%95%e8%ae%a9%e5%86%85%e5%ae%b9%e9%a1%b6%e9%83%a8%e5%af%b9%e9%bd%90%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3544\/","title":{"rendered":"\u4f7f\u7528 CSS Grid \u5e03\u5c40\u65f6\u5982\u4f55\u8ba9\u5185\u5bb9\u9876\u90e8\u5bf9\u9f50\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173105480284314.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 CSS Grid \u5e03\u5c40\u65f6\u5982\u4f55\u8ba9\u5185\u5bb9\u9876\u90e8\u5bf9\u9f50\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 CSS Grid \u5e03\u5c40\u65f6\u5982\u4f55\u8ba9\u5185\u5bb9\u9876\u90e8\u5bf9\u9f50\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u89e3\u51b3\u4f7f\u7528  grid \u5e03\u5c40\u65f6\u5185\u5bb9\u4e0d\u9876\u90e8\u5bf9\u9f50\u7684\u95ee\u9898\uff1f<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0\uff1a<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 css grid \u5e03\u5c40\u521b\u5efa\u4e00\u4e2a\u4e09\u680f\u5e03\u5c40\u65f6\uff0c\u9047\u5230\u4e2d\u95f4\u548c\u53f3\u4fa7\u5185\u5bb9\u4e0d\u9876\u90e8\u5bf9\u9f50\u7684\u60c5\u51b5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>1\n2 3\n  4\n  5 6\n    7<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u800c\u671f\u671b\u7684\u663e\u793a\u5f62\u5f0f\u5e94\u8be5\u662f\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>1 3 6\n2 4 7\n  5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u539f\u56e0\u5206\u6790\uff1a<\/strong><\/p>\n<p>\u539f\u5148\u7684 css \u4ee3\u7801\u4e2d\u7f3a\u5c11\u4e86 grid-auto-flow: dense \u5c5e\u6027\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5728 fruit-grid \u7c7b\u4e0a\u6dfb\u52a0 grid-auto-flow: dense \u5c5e\u6027\uff0c\u53ef\u4ee5\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<pre>.fruit-grid {\n  display: grid;\n  grid-template-columns: repeat(3, 1fr);\n  gap: 10px;\n  align-items: start;\n  grid-auto-flow: dense;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>grid-auto-flow: dense \u5c5e\u6027\u53ef\u8ba9\u5143\u7d20\u5c3d\u53ef\u80fd\u5730\u4f7f\u7528\u524d\u9762\u7a7a\u7684\u7f51\u683c\uff0c\u800c\u4e0d\u662f\u521b\u5efa\u65b0\u7684\u7f51\u683c\u884c\u6216\u5217\u3002\u4ece\u800c\u5b9e\u73b0\u9876\u90e8\u5bf9\u9f50\u3002<\/p>\n<p><strong>\u4fee\u6b63\u540e\u7684\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>&lt;div class=\"fruit-grid\"&gt;\n  &lt;div class=\"fruit\"&gt;hello1&lt;\/div&gt;\n  &lt;div class=\"fruit\"&gt;hello2&lt;\/div&gt;\n  &lt;div class=\"fruit\"&gt;hello3&lt;\/div&gt;\n  &lt;div class=\"fruit\"&gt;hello4&lt;\/div&gt;\n  &lt;div class=\"fruit\"&gt;hello5&lt;\/div&gt;\n  &lt;div class=\"fruit\"&gt;hello6&lt;\/div&gt;\n  &lt;div class=\"fruit\"&gt;hello7&lt;\/div&gt;\n&lt;\/div&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>.fruit-grid {\n  display: grid;\n  grid-template-columns: repeat(3, 1fr);\n  gap: 10px;\n  align-items: start;\n  grid-auto-flow: dense;\n}\n\n.fruit {\n  width: 100%;\n  margin-bottom: 10px;\n}\n\n.fruit:nth-child(1),\n.fruit:nth-child(2) {\n  grid-column: 1;\n}\n\n.fruit:nth-child(3),\n.fruit:nth-child(4),\n.fruit:nth-child(5) {\n  grid-column: 2;\n}\n\n.fruit:nth-child(6),\n.fruit:nth-child(7) {\n  grid-column: 3;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528 CSS Grid \u5e03\u5c40\u65f6\u5982\u4f55\u8ba9\u5185\u5bb9\u9876\u90e8\u5bf9\u9f50\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3\u4f7f\u7528 grid \u5e03\u5c40\u65f6\u5185\u5bb9\u4e0d\u9876\u90e8\u5bf9\u9f50\u7684\u95ee\u9898\uff1f \u95ee\u9898\u63cf\u8ff0\uff1a \u5728\u4f7f\u7528 css grid \u5e03\u5c40\u521b\u5efa\u4e00\u4e2a\u4e09\u680f\u5e03\u5c40\u65f6\uff0c\u9047\u5230\u4e2d\u95f4\u548c\u53f3\u4fa7\u5185\u5bb9\u4e0d\u9876\u90e8\u5bf9\u9f50\u7684\u60c5\u51b5\uff0c\u5982\u4e0b\u6240\u793a\uff1a 1 2 3 4 5 6 7 \u767b\u5f55\u540e\u590d\u5236 \u800c\u671f\u671b\u7684\u663e\u793a\u5f62\u5f0f\u5e94\u8be5\u662f\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1 3 6 2 4 7 5 \u767b\u5f55\u540e\u590d\u5236 \u539f\u56e0\u5206\u6790\uff1a \u539f\u5148\u7684 css \u4ee3\u7801\u4e2d\u7f3a\u5c11\u4e86 grid-auto-flow: dense \u5c5e\u6027\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u5728 fruit-grid \u7c7b\u4e0a\u6dfb\u52a0 grid-auto-flow: dense \u5c5e\u6027\uff0c\u53ef\u4ee5\u89e3\u51b3\u6b64\u95ee\u9898\u3002 .fruit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-items: start; grid-auto-flow: dense; } \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3544","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3544"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3544\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}