{"id":105,"date":"2025-09-06T21:12:44","date_gmt":"2025-09-06T13:12:44","guid":{"rendered":"http:\/\/101.42.104.90\/?p=105"},"modified":"2025-09-06T21:26:58","modified_gmt":"2025-09-06T13:26:58","slug":"%e8%a2%ab%e7%8e%b0%e4%bb%a3-css-%e5%b8%83%e5%b1%80%e7%88%bd%e5%88%b0%e4%ba%86%ef%bc%81%e8%bf%99%e5%87%a0%e4%b8%aa%e6%8a%80%e5%b7%a7%e5%bd%bb%e5%ba%95%e6%94%b9%e5%8f%98%e6%88%91%e7%9a%84%e5%bc%80","status":"publish","type":"post","link":"http:\/\/yuemustory.fun\/index.php\/2025\/09\/06\/%e8%a2%ab%e7%8e%b0%e4%bb%a3-css-%e5%b8%83%e5%b1%80%e7%88%bd%e5%88%b0%e4%ba%86%ef%bc%81%e8%bf%99%e5%87%a0%e4%b8%aa%e6%8a%80%e5%b7%a7%e5%bd%bb%e5%ba%95%e6%94%b9%e5%8f%98%e6%88%91%e7%9a%84%e5%bc%80\/","title":{"rendered":"\u88ab\u73b0\u4ee3 CSS \u5e03\u5c40\u723d\u5230\u4e86\uff01\u8fd9\u51e0\u4e2a\u6280\u5de7\u5f7b\u5e95\u6539\u53d8\u6211\u7684\u5f00\u53d1\u4e60\u60ef"},"content":{"rendered":"<p>\u6700\u8fd1\u91cd\u6784\u8001\u9879\u76ee\uff0c\u628a\u4ee5\u524d\u7528\u6d6e\u52a8\u3001\u5b9a\u4f4d\u5806\u51fa\u6765\u7684\u5e03\u5c40\uff0c\u5168\u6362\u6210\u4e86\u73b0\u4ee3 CSS \u65b9\u6848 \u2014\u2014Grid\u3001Flexbox\u3001Container Queries \u8fd9\u4e9b\uff0c\u5199\u5b8c\u76f4\u63a5\u611f\u53f9\uff1a\u539f\u6765\u5e03\u5c40\u53ef\u4ee5\u8fd9\u4e48\u7701\u5fc3\uff01\u4eca\u5929\u5c31\u804a\u804a\u5b9e\u6218\u91cc\u6700\u5e38\u7528\u7684\u51e0\u4e2a\u6280\u5de7\uff0c\u4ee5\u53ca\u90a3\u4e9b \u201c\u65e9\u77e5\u9053\u65e9\u7701\u4e8b\u201d \u7684\u7ecf\u9a8c\uff5e<\/p>\n<p>\u9996\u5148\u5fc5\u987b\u5439\u7206 <strong>Grid \u5e03\u5c40<\/strong>\uff0c\u5c24\u5176\u662f\u505a\u6574\u4f53\u9875\u9762\u6846\u67b6\u7684\u65f6\u5019\uff0c\u4ee5\u524d\u7528 \u201cheader+main+footer\u201d \u8fd8\u8981\u7b97 margin\u3001\u6e05\u6d6e\u52a8\uff0c\u73b0\u5728\u51e0\u884c\u4ee3\u7801\u5c31\u80fd\u641e\u5b9a\u3002\u6bd4\u5982\u7ecf\u5178\u7684 \u201c\u4e09\u680f\u5e03\u5c40\u201d\uff08\u5bfc\u822a + \u5185\u5bb9 + \u4fa7\u8fb9\u680f\uff09\uff0c\u7528<code>grid-template-areas<\/code>\u76f4\u63a5 \u201c\u753b\u201d \u7ed3\u6784\uff0c\u8c01\u5728\u54ea\u4e2a\u4f4d\u7f6e\u4e00\u76ee\u4e86\u7136\uff1a<\/p>\n<pre><code>.layout {\n\n&amp;#x20; display: grid;\n\n&amp;#x20; grid-template-areas:&amp;#x20;\n\n&amp;#x20;   &quot;header header header&quot;\n\n&amp;#x20;   &quot;nav content sidebar&quot;\n\n&amp;#x20;   &quot;footer footer footer&quot;;\n\n&amp;#x20; grid-template-columns: 200px 1fr 200px; \/\\* \u4e2d\u95f4\u5185\u5bb9\u81ea\u9002\u5e94 \\*\/\n\n&amp;#x20; gap: 1rem; \/\\* \u81ea\u5e26\u95f4\u8ddd\uff0c\u4e0d\u7528\u7b97margin \\*\/\n\n}<\/code><\/pre>\n<p>\u6700\u9999\u7684\u662f\u54cd\u5e94\u5f0f\u8c03\u6574\uff0c\u6bd4\u5982\u79fb\u52a8\u7aef\u8981\u628a\u4e09\u680f\u53e0\u6210\u4e00\u680f\uff0c\u53ea\u8981\u6539\u4e0b<code>grid-template-areas<\/code>\u548c<code>grid-template-columns<\/code>\uff0c\u4e0d\u7528\u52a8 HTML \u7ed3\u6784\uff0c\u6bd4\u4ee5\u524d\u5199 N \u4e2a\u5a92\u4f53\u67e5\u8be2\u6539\u6d6e\u52a8\u65b9\u4fbf\u592a\u591a\u3002<\/p>\n<p>\u7136\u540e\u662f <strong>Flexbox<\/strong>\uff0c\u505a\u5361\u7247\u5217\u8868\u3001\u7ec4\u4ef6\u5185\u90e8\u5bf9\u9f50\u7684\u65f6\u5019\u7b80\u76f4\u662f\u795e\u5668\u3002\u4ee5\u524d\u5199\u5361\u7247\u5e03\u5c40\uff0c\u8981\u7b97 \u201c\u4e00\u884c\u80fd\u653e\u51e0\u4e2a\u201d\u201c\u4e0d\u591f\u5bbd\u65f6\u6362\u884c\u201d\uff0c\u73b0\u5728\u7528<code>flex: 1 1 300px<\/code>\u5c31\u80fd\u5b9e\u73b0 \u201c\u5361\u7247\u6700\u5c0f 300px\uff0c\u591f\u5bbd\u5c31\u5e73\u5206\u7a7a\u95f4\u201d\uff0c\u518d\u52a0\u4e0a<code>flex-wrap: wrap<\/code>\u81ea\u52a8\u6362\u884c\uff0c\u7701\u4e86\u4e00\u5806\u8ba1\u7b97\uff1a<\/p>\n<pre><code>.card-container {\n\n&amp;#x20; display: flex;\n\n&amp;#x20; flex-wrap: wrap;\n\n&amp;#x20; gap: 1rem;\n\n}\n\n.card {\n\n&amp;#x20; flex: 1 1 300px; \/\\* \u4f38\u7f29\u6027+\u57fa\u51c6\u5bbd\u5ea6\uff0c\u5b8c\u7f8e\u9002\u914d\u4e0d\u540c\u5c4f\u5e55 \\*\/\n\n}<\/code><\/pre>\n<p>\u8fd8\u6709\u4e2a\u5c0f\u7ec6\u8282\uff1a\u7528<code>flex-direction: column<\/code>+<code>flex: 1<\/code>\u80fd\u8ba9\u5361\u7247\u5185\u5bb9 \u201c\u6491\u6ee1\u5269\u4f59\u9ad8\u5ea6\u201d\uff0c\u6bd4\u5982\u5361\u7247\u91cc\u7684\u6587\u5b57\u533a\u4e0d\u7ba1\u5185\u5bb9\u591a\u5c11\uff0c\u90fd\u548c\u5176\u4ed6\u5361\u7247\u5bf9\u9f50\uff0c\u4ee5\u524d\u8981\u9760 JS \u7b97\u9ad8\u5ea6\uff0c\u73b0\u5728 CSS \u4e00\u884c\u641e\u5b9a\uff0c\u592a\u723d\u4e86\uff01<\/p>\n<p>\u4eca\u5e74\u65b0\u5b66\u7684 <strong>Container Queries<\/strong> \u66f4\u662f\u98a0\u8986\u8ba4\u77e5 \u2014\u2014 \u4ee5\u524d\u54cd\u5e94\u5f0f\u53ea\u80fd \u201c\u770b\u5c4f\u5e55\u5bbd\u5ea6\u201d\uff0c\u73b0\u5728\u80fd \u201c\u770b\u7236\u5bb9\u5668\u5bbd\u5ea6\u201d \u4e86\uff01\u6bd4\u5982\u5361\u7247\u5728\u7a84\u5bb9\u5668\u91cc\u662f\u4e0a\u4e0b\u5e03\u5c40\uff0c\u653e\u5230\u5bbd\u5bb9\u5668\u91cc\u81ea\u52a8\u53d8\u6210\u5de6\u53f3\u5e03\u5c40\uff0c\u4e0d\u7528\u518d\u7ea0\u7ed3 \u201c\u5c4f\u5e55\u591a\u5927\u65f6\u6539\u6837\u5f0f\u201d\uff0c\u76f4\u63a5\u76ef\u7740\u7236\u5bb9\u5668\u5199\u89c4\u5219\uff1a<\/p>\n<pre><code>.card-container {\n\n&amp;#x20; container-type: inline-size; \/\\* \u5f00\u542f\u5bb9\u5668\u67e5\u8be2 \\*\/\n\n}\n\n@container (min-width: 400px) {\n\n&amp;#x20; .card {\n\n&amp;#x20;   flex-direction: row; \/\\* \u7236\u5bb9\u5668\u591f\u5bbd\uff0c\u5361\u7247\u6a2a\u6392 \\*\/\n\n&amp;#x20; }\n\n}<\/code><\/pre>\n<p>\u6bd4\u5982\u5728\u4fa7\u8fb9\u680f\u91cc\u7684\u5361\u7247\u662f\u7ad6\u6392\uff0c\u653e\u5230\u4e3b\u5185\u5bb9\u533a\u81ea\u52a8\u6a2a\u6392\uff0c\u5b8c\u5168\u4e0d\u7528\u5199\u5a92\u4f53\u67e5\u8be2\uff0c\u9002\u914d\u903b\u8f91\u66f4\u76f4\u89c2\u4e86\u3002<\/p>\n<p>\u4e0d\u8fc7\u4e5f\u8e29\u8fc7\u4e24\u4e2a\u5c0f\u5751\uff1a\u4e00\u662f\u521a\u5f00\u59cb\u7528 Grid \u7684\u65f6\u5019\uff0c\u603b\u5fd8\u4e86<code>gap<\/code>\u548c<code>margin<\/code>\u7684\u533a\u522b\uff0c\u52a0\u4e86<code>gap<\/code>\u53c8\u52a0<code>margin<\/code>\u5bfc\u81f4\u95f4\u8ddd\u7ffb\u500d\uff1b\u4e8c\u662f Container Queries \u76ee\u524d\u8fd8\u9700\u8981\u7ed9\u7236\u5bb9\u5668\u52a0<code>container-type<\/code>\uff0c\u5fd8\u4e86\u52a0\u5c31\u6ca1\u6548\u679c\uff0c\u540e\u6765\u517b\u6210\u4e86 \u201c\u5199\u5bb9\u5668\u67e5\u8be2\u5148\u5f00\u5bb9\u5668\u7c7b\u578b\u201d \u7684\u4e60\u60ef\u3002<\/p>\n<p>\u53e6\u5916\uff0c<strong>CSS \u53d8\u91cf<\/strong>\u4e00\u5b9a\u8981\u7528\uff01\u628a\u95f4\u8ddd\u3001\u989c\u8272\u3001\u57fa\u51c6\u5bbd\u5ea6\u5b9a\u4e49\u6210\u53d8\u91cf\uff0c\u6bd4\u5982<code>--spacing-unit: 8px<\/code>\uff0c\u540e\u9762\u6539\u6837\u5f0f\u7684\u65f6\u5019\u4e0d\u7528\u5230\u5904\u627e\u6570\u503c\uff0c\u76f4\u63a5\u6539\u53d8\u91cf\u5c31\u884c\u3002\u6211\u8fd8\u4f1a\u7528<code>clamp()<\/code>\u505a\u81ea\u9002\u5e94\u5bbd\u5ea6\uff0c\u6bd4\u5982<code>--card-width: clamp(300px, 30vw, 400px)<\/code>\uff0c\u5361\u7247\u5bbd\u5ea6\u65e2\u4e0d\u4f1a\u592a\u5c0f\u4e5f\u4e0d\u4f1a\u592a\u5927\uff0c\u9002\u914d\u5404\u79cd\u5c4f\u5e55\u521a\u597d\u3002<\/p>\n<p>\u6700\u540e\u60f3\u8bf4\uff0c\u73b0\u5728\u5199 CSS \u771f\u7684\u4e0d\u7528\u518d \u201c\u59d4\u5c48\u81ea\u5df1\u201d \u4e86\uff0c\u522b\u518d\u4f9d\u8d56\u6d6e\u52a8\u548c\u5b9a\u4f4d\u5806\u5e03\u5c40\uff0c\u8bd5\u8bd5 Grid\u3001Flexbox \u8fd9\u4e9b\u73b0\u4ee3\u65b9\u6848\uff0c\u6548\u7387\u80fd\u63d0\u4e00\u500d\u4e0d\u6b62\u3002\u5982\u679c\u4f60\u4eec\u6709 \u201c\u7528 CSS \u53d8\u91cf\u505a\u4e3b\u9898\u5207\u6362\u201d\u201cGrid \u5d4c\u5957\u5e03\u5c40\u201d \u7684\u7ecf\u9a8c\uff0c\u4e5f\u6b22\u8fce\u8bc4\u8bba\u533a\u5206\u4eab\uff0c\u4e00\u8d77\u5c11\u5199\u5197\u4f59\u4ee3\u7801\uff5e \u2728<\/p>","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u91cd\u6784\u8001\u9879\u76ee\uff0c\u628a\u4ee5\u524d\u7528\u6d6e\u52a8\u3001\u5b9a\u4f4d\u5806\u51fa\u6765\u7684\u5e03\u5c40\uff0c\u5168\u6362\u6210\u4e86\u73b0\u4ee3 CSS \u65b9\u6848 \u2014\u2014Grid\u3001Flexbox\u3001Co [&hellip;]<\/p>","protected":false},"author":1,"featured_media":107,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-picture"],"_links":{"self":[{"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":2,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":115,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/posts\/105\/revisions\/115"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/media\/107"}],"wp:attachment":[{"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yuemustory.fun\/index.php\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}