{"id":866,"date":"2025-12-22T09:11:42","date_gmt":"2025-12-22T01:11:42","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=866"},"modified":"2025-12-22T09:11:42","modified_gmt":"2025-12-22T01:11:42","slug":"css%e5%ae%9e%e7%8e%b0%e5%85%83%e7%b4%a0%e6%92%91%e6%bb%a1%e5%89%a9%e4%bd%99%e7%a9%ba%e9%97%b4%e7%9a%84%e4%ba%94%e7%a7%8d%e6%96%b9%e6%b3%95-3","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/css%e5%ae%9e%e7%8e%b0%e5%85%83%e7%b4%a0%e6%92%91%e6%bb%a1%e5%89%a9%e4%bd%99%e7%a9%ba%e9%97%b4%e7%9a%84%e4%ba%94%e7%a7%8d%e6%96%b9%e6%b3%95-3\/","title":{"rendered":"CSS\u5b9e\u73b0\u5143\u7d20\u6491\u6ee1\u5269\u4f59\u7a7a\u95f4\u7684\u4e94\u79cd\u65b9\u6cd5"},"content":{"rendered":"\n<p>CSS \u5b9e\u73b0\u5143\u7d20\u6491\u6ee1\u5269\u4f59\u7a7a\u95f4\u7684\u4e94\u79cd\u5e38\u89c1\u65b9\u6cd5\uff082025 \u5e74\u4e3b\u6d41\u5199\u6cd5\uff09\u5728\u5e03\u5c40\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u8ba9\u67d0\u4e2a\u5143\u7d20\u81ea\u52a8\u6491\u6ee1\u7236\u5bb9\u5668\u7684\u5269\u4f59\u7a7a\u95f4\uff08\u5782\u76f4\u6216\u6c34\u5e73\uff09\u3002\u4ee5\u4e0b\u662f\u4e94\u79cd\u6700\u5e38\u7528\u3001\u6700\u5b9e\u7528\u7684\u65b9\u6cd5\uff0c\u9644\u5e26\u9002\u7528\u573a\u666f\u548c\u4f18\u7f3a\u70b9\u5bf9\u6bd4\u30021. Flexbox\uff08\u6700\u5e38\u7528\uff0c\u63a8\u8350\uff09<\/p>\n\n\n\n<p>css<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  display: flex;\n  flex-direction: column; \/* \u5782\u76f4\u5e03\u5c40\u65f6 *\/\n  height: 100vh;          \/* \u7236\u5bb9\u5668\u8981\u6709\u660e\u786e\u9ad8\u5ea6 *\/\n}\n\n.main {\n  flex: 1;                \/* \u5173\u952e\uff1a1 \u8868\u793a\u5360\u6ee1\u5269\u4f59\u7a7a\u95f4 *\/\n  overflow: auto;         \/* \u9632\u6b62\u5185\u5bb9\u6ea2\u51fa\u65f6\u6491\u7834 *\/\n}\n<\/pre><\/div>\n\n\n<p>html<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;div class=&quot;container&quot;&gt;\n  &amp;lt;header&gt;\u5934\u90e8\u56fa\u5b9a\u9ad8\u5ea6&amp;lt;\/header&gt;\n  &amp;lt;main class=&quot;main&quot;&gt;\u6491\u6ee1\u5269\u4f59\u7a7a\u95f4&amp;lt;\/main&gt;\n  &amp;lt;footer&gt;\u5e95\u90e8\u56fa\u5b9a\u9ad8\u5ea6&amp;lt;\/footer&gt;\n&amp;lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p>\u4f18\u70b9\uff1a\u7b80\u5355\u3001\u76f4\u89c2\u3001\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u6781\u597d\uff08IE11+\uff09<br>\u7f3a\u70b9\uff1a\u9700\u7236\u5bb9\u5668\u6709\u660e\u786e\u9ad8\u5ea62. Grid\uff08\u73b0\u4ee3\u5e03\u5c40\u795e\u5668\uff09<\/p>\n\n\n\n<p>css<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  display: grid;\n  grid-template-rows: auto 1fr auto; \/* \u5934\u90e8\u3001\u4e3b\u4f53\u3001\u5c3e\u90e8 *\/\n  height: 100vh;\n}\n<\/pre><\/div>\n\n\n<p>html<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;div class=&quot;container&quot;&gt;\n  &amp;lt;header&gt;\u5934\u90e8&amp;lt;\/header&gt;\n  &amp;lt;main&gt;\u6491\u6ee1\u5269\u4f59\u7a7a\u95f4&amp;lt;\/main&gt;\n  &amp;lt;footer&gt;\u5e95\u90e8&amp;lt;\/footer&gt;\n&amp;lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p>\u4f18\u70b9\uff1a\u4ee3\u7801\u6700\u7b80\u6d01\uff0c\u8bed\u4e49\u6e05\u6670\uff0c\u6613\u4e8e\u7ef4\u62a4<br>\u7f3a\u70b9\uff1aIE11 \u4e0d\u652f\u6301\uff08\u4f46\u73b0\u4ee3\u9879\u76ee\u57fa\u672c\u65e0\u6b64\u987e\u8651\uff093. \u7edd\u5bf9\u5b9a\u4f4d + calc\uff08\u517c\u5bb9\u6027\u6700\u597d\uff09<\/p>\n\n\n\n<p>css<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  position: relative;\n  height: 100vh;\n}\n\n.header, .footer {\n  height: 60px;\n}\n\n.main {\n  position: absolute;\n  top: 60px;\n  bottom: 60px;\n  left: 0;\n  right: 0;\n  overflow: auto;\n}\n<\/pre><\/div>\n\n\n<p>\u6216\u7528 calc\uff08\u66f4\u7075\u6d3b\uff09\uff1a<\/p>\n\n\n\n<p>css<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.main {\n  height: calc(100vh - 120px); \/* \u51cf\u53bb\u5934\u90e8+\u5e95\u90e8\u603b\u9ad8\u5ea6 *\/\n}\n<\/pre><\/div>\n\n\n<p>\u4f18\u70b9\uff1a\u517c\u5bb9\u6027\u6781\u5f3a\uff08IE8+\uff09<br>\u7f3a\u70b9\uff1a\u9700\u624b\u52a8\u8ba1\u7b97\u9ad8\u5ea6\uff0c\u7ef4\u62a4\u9ebb\u70e64. Flexbox + \u8d1f margin\uff08\u7ecf\u5178 hack \u5199\u6cd5\uff09<\/p>\n\n\n\n<p>css<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  display: flex;\n  flex-direction: column;\n  min-height: 100vh;\n}\n\n.content {\n  flex: 1;\n}\n\n.footer {\n  margin-top: -60px; \/* \u5e95\u90e8\u9ad8\u5ea6\u7684\u8d1f\u503c *\/\n}\n<\/pre><\/div>\n\n\n<p>\u4f18\u70b9\uff1a\u5728\u67d0\u4e9b\u8001\u9879\u76ee\u4e2d\u4ecd\u6709\u7528\u6b66\u4e4b\u5730<br>\u7f3a\u70b9\uff1ahack \u6027\u8d28\uff0c\u4e0d\u591f\u4f18\u96c5\uff0c\u4e0d\u63a8\u8350\u65b0\u9879\u76ee5. CSS \u53d8\u91cf + calc\uff08\u9ad8\u5ea6\u52a8\u6001\u53d8\u5316\u65f6\uff09<\/p>\n\n\n\n<p>css<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n:root {\n  --header-height: 60px;\n  --footer-height: 60px;\n}\n\n.container {\n  min-height: 100vh;\n}\n\n.main {\n  height: calc(100vh - var(--header-height) - var(--footer-height));\n  min-height: calc(100vh - var(--header-height) - var(--footer-height));\n}\n<\/pre><\/div>\n\n\n<p>\u4f18\u70b9\uff1a\u9ad8\u5ea6\u53ef\u901a\u8fc7 JS \u6216 CSS \u53d8\u91cf\u52a8\u6001\u4fee\u6539<br>\u7f3a\u70b9\uff1a\u4ecd\u9700\u624b\u52a8\u8ba1\u7b97\u516d\u79cd\u65b9\u6cd5\u5bf9\u6bd4\u8868\uff082025 \u5e74\u63a8\u8350\u4f18\u5148\u7ea7\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u6392\u540d<\/th><th>\u65b9\u6cd5<\/th><th>\u6d4f\u89c8\u5668\u517c\u5bb9\u6027<\/th><th>\u4ee3\u7801\u7b80\u6d01\u5ea6<\/th><th>\u7ef4\u62a4\u6027<\/th><th>\u63a8\u8350\u573a\u666f<\/th><\/tr><tr><td>1<\/td><td>Flexbox (flex:1)<\/td><td>IE11+<\/td><td>\u2605\u2605\u2605\u2605\u2605<\/td><td>\u2605\u2605\u2605\u2605\u2605<\/td><td>99% \u73b0\u4ee3\u9879\u76ee<\/td><\/tr><tr><td>2<\/td><td>Grid (1fr)<\/td><td>IE11 \u4e0d\u652f\u6301<\/td><td>\u2605\u2605\u2605\u2605\u2605<\/td><td>\u2605\u2605\u2605\u2605\u2605<\/td><td>\u73b0\u4ee3\u9879\u76ee\u9996\u9009<\/td><\/tr><tr><td>3<\/td><td>\u7edd\u5bf9\u5b9a\u4f4d + calc<\/td><td>IE8+<\/td><td>\u2605\u2605\u2605<\/td><td>\u2605\u2605\u2605<\/td><td>\u9700\u8981\u517c\u5bb9\u8001\u6d4f\u89c8\u5668<\/td><\/tr><tr><td>4<\/td><td>CSS \u53d8\u91cf + calc<\/td><td>IE \u4e0d\u652f\u6301<\/td><td>\u2605\u2605\u2605\u2605<\/td><td>\u2605\u2605\u2605\u2605<\/td><td>\u9ad8\u5ea6\u52a8\u6001\u53d8\u5316\u573a\u666f<\/td><\/tr><tr><td>5<\/td><td>\u8d1f margin hack<\/td><td>IE8+<\/td><td>\u2605\u2605<\/td><td>\u2605<\/td><td>\u8001\u9879\u76ee\u8fc7\u6e21<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4e00\u53e5\u8bdd\u8bb0\u4f4f\uff1a<br>\u73b0\u4ee3\u9879\u76ee\u7528 Flexbox \u6216 Grid \u5373\u53ef\uff0cflex: 1 \u6216 1fr \u662f\u6700\u4f18\u96c5\u7684\u5199\u6cd5\u3002\u989d\u5916\u5c0f\u6280\u5de7\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u7236\u5bb9\u5668\u9ad8\u5ea6\u662f 100% \u800c\u975e\u56fa\u5b9a\u503c\uff0c\u8bb0\u5f97\u7ed9 html \u548c body \u4e5f\u8bbe\u7f6e height: 100%\u3002<\/li>\n\n\n\n<li>\u9700\u8981\u6c34\u5e73\u6491\u6ee1\u5269\u4f59\u7a7a\u95f4\u65f6\uff0cflex-direction: row + flex: 1 \u540c\u6837\u9002\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u6709\u5177\u4f53\u5e03\u5c40\u573a\u666f\uff08\u6bd4\u5982\u4fa7\u8fb9\u680f + \u4e3b\u5185\u5bb9 + \u5e95\u90e8\u56fa\u5b9a\uff09\uff0c\u53ef\u4ee5\u544a\u8bc9\u6211\uff0c\u6211\u5e2e\u4f60\u5199\u6700\u4f18\u89e3\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS \u5b9e\u73b0\u5143\u7d20\u6491\u6ee1\u5269\u4f59\u7a7a\u95f4\u7684\u4e94\u79cd\u5e38\u89c1\u65b9\u6cd5\uff082025 \u5e74\u4e3b\u6d41\u5199\u6cd5\uff09\u5728\u5e03\u5c40\u4e2d\uff0c\u6211\u4eec&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/css%e5%ae%9e%e7%8e%b0%e5%85%83%e7%b4%a0%e6%92%91%e6%bb%a1%e5%89%a9%e4%bd%99%e7%a9%ba%e9%97%b4%e7%9a%84%e4%ba%94%e7%a7%8d%e6%96%b9%e6%b3%95-3\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-866","post","type-post","status-publish","format-standard","hentry","category-css"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=866"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/866\/revisions"}],"predecessor-version":[{"id":867,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/866\/revisions\/867"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}