{"id":16,"date":"2025-11-20T16:35:15","date_gmt":"2025-11-20T08:35:15","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=16"},"modified":"2025-11-20T16:35:15","modified_gmt":"2025-11-20T08:35:15","slug":"html%e4%b8%ad%e4%bd%bf%e7%94%a8flex%e5%b8%83%e5%b1%80%e5%ae%9e%e7%8e%b0%e5%8f%8c%e8%a1%8c%e5%a4%b9%e6%89%b9%e6%95%88%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/11\/20\/html%e4%b8%ad%e4%bd%bf%e7%94%a8flex%e5%b8%83%e5%b1%80%e5%ae%9e%e7%8e%b0%e5%8f%8c%e8%a1%8c%e5%a4%b9%e6%89%b9%e6%95%88%e6%9e%9c\/","title":{"rendered":"HTML\u4e2d\u4f7f\u7528Flex\u5e03\u5c40\u5b9e\u73b0\u53cc\u884c\u5939\u6279\u6548\u679c"},"content":{"rendered":"\n<p>\u5728 HTML \u4e2d\u4f7f\u7528&nbsp;<strong>Flexbox<\/strong>&nbsp;\u5e03\u5c40\u5b9e\u73b0\u201c\u53cc\u884c\u5939\u6279\u6548\u679c\u201d\u901a\u5e38\u6307\u7684\u662f\u5728\u5bb9\u5668\u4e2d\u6392\u5217\u4e24\u4e2a\u5143\u7d20\uff0c\u4e14\u8fd9\u4e24\u4e2a\u5143\u7d20\u5728\u89c6\u89c9\u4e0a\u8868\u73b0\u4e3a\u4e24\u884c\u4e92\u76f8\u5305\u56f4\u6216\u5939\u4f4f\u7684\u6548\u679c\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u8fd9\u7c7b\u6548\u679c\u53ef\u80fd\u662f\u4e0a\u9762\u4e00\u884c\u5143\u7d20\u5c45\u4e2d\uff0c\u4e0b\u9762\u4e00\u884c\u5143\u7d20\u4e5f\u5c45\u4e2d\uff0c\u4e24\u8005\u6709\u4e00\u4e9b\u95f4\u8ddd\uff0c\u5f62\u6210\u201c\u5939\u6279\u201d\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 Flexbox \u6765\u8f7b\u677e\u5b9e\u73b0\u8fd9\u4e2a\u5e03\u5c40\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u73b0\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\u4ee3\u7801\uff1a<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">HTML:<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html lang=&quot;en&quot;&gt;\n&amp;lt;head&gt;\n    &amp;lt;meta charset=&quot;UTF-8&quot;&gt;\n    &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &amp;lt;title&gt;Flex \u5e03\u5c40 \u53cc\u884c\u5939\u6279\u6548\u679c&amp;lt;\/title&gt;\n    &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt;\n&amp;lt;\/head&gt;\n&amp;lt;body&gt;\n\n    &amp;lt;div class=&quot;container&quot;&gt;\n        &amp;lt;div class=&quot;top-row&quot;&gt;\n            &amp;lt;div class=&quot;item&quot;&gt;\u4e0a\u884c1&amp;lt;\/div&gt;\n            &amp;lt;div class=&quot;item&quot;&gt;\u4e0a\u884c2&amp;lt;\/div&gt;\n            &amp;lt;div class=&quot;item&quot;&gt;\u4e0a\u884c3&amp;lt;\/div&gt;\n        &amp;lt;\/div&gt;\n        &amp;lt;div class=&quot;bottom-row&quot;&gt;\n            &amp;lt;div class=&quot;item&quot;&gt;\u4e0b\u884c1&amp;lt;\/div&gt;\n            &amp;lt;div class=&quot;item&quot;&gt;\u4e0b\u884c2&amp;lt;\/div&gt;\n            &amp;lt;div class=&quot;item&quot;&gt;\u4e0b\u884c3&amp;lt;\/div&gt;\n        &amp;lt;\/div&gt;\n    &amp;lt;\/div&gt;\n\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">CSS (styles.css):<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nbody, html {\n    margin: 0;\n    padding: 0;\n    height: 100%;\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    background-color: #f4f4f4;\n}\n\n.container {\n    display: flex;\n    flex-direction: column;\n    justify-content: center;\n    align-items: center;\n    text-align: center;\n    gap: 20px; \/* \u4e0a\u4e0b\u4e24\u884c\u4e4b\u95f4\u7684\u95f4\u8ddd *\/\n}\n\n.top-row, .bottom-row {\n    display: flex;\n    justify-content: center; \/* \u6c34\u5e73\u5c45\u4e2d *\/\n    gap: 15px; \/* \u6bcf\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684\u95f4\u8ddd *\/\n}\n\n.item {\n    background-color: #4CAF50;\n    color: white;\n    padding: 10px 20px;\n    border-radius: 5px;\n    font-size: 16px;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Flexbox \u5e03\u5c40<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>.container<\/code>\u00a0\u4f7f\u7528\u00a0<code>flex-direction: column;<\/code>\u00a0\u5c06\u5b50\u5143\u7d20\u5782\u76f4\u6392\u5217\u3002\u8fd9\u4f7f\u5f97\u00a0<code>.top-row<\/code>\u00a0\u548c\u00a0<code>.bottom-row<\/code>\u00a0\u5728\u5782\u76f4\u65b9\u5411\u4e0a\u5806\u53e0\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u00a0<code>gap<\/code>\u00a0\u5c5e\u6027\u6765\u4e3a\u4e0a\u4e0b\u4e24\u884c\u4e4b\u95f4\u8bbe\u7f6e\u95f4\u8ddd\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4e0a\u4e0b\u4e24\u884c\uff08<code>.top-row<\/code>\u00a0\u548c\u00a0<code>.bottom-row<\/code>\uff09<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u4e00\u884c\u90fd\u4f7f\u7528\u00a0<code>display: flex;<\/code>\u00a0\u4f7f\u5176\u5b50\u5143\u7d20\u6c34\u5e73\u6392\u5217\u3002<\/li>\n\n\n\n<li><code>justify-content: center;<\/code>\u00a0\u786e\u4fdd\u6bcf\u884c\u4e2d\u7684\u5143\u7d20\u6c34\u5e73\u5c45\u4e2d\u3002<\/li>\n\n\n\n<li><code>gap<\/code>\u00a0\u7528\u4e8e\u8bbe\u7f6e\u884c\u5185\u5143\u7d20\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u6bcf\u4e2a\u5143\u7d20\uff08<code>.item<\/code>\uff09<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u4e2a\u00a0<code>.item<\/code>\u00a0\u4f7f\u7528\u80cc\u666f\u989c\u8272\u3001\u5185\u8fb9\u8ddd\u3001\u5706\u89d2\u548c\u5b57\u4f53\u5927\u5c0f\u8fdb\u884c\u6837\u5f0f\u5316\u3002<\/li>\n\n\n\n<li><code>border-radius: 5px;<\/code>\u00a0\u8ba9\u6bcf\u4e2a\u5143\u7d20\u7684\u89d2\u843d\u53d8\u5f97\u5706\u6da6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u6548\u679c\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0a\u9762\u4e00\u884c (<code>.top-row<\/code>) \u548c\u4e0b\u9762\u4e00\u884c (<code>.bottom-row<\/code>) \u90fd\u662f\u6c34\u5e73\u5c45\u4e2d\u7684\uff0c\u5e76\u4e14\u6bcf\u884c\u4e4b\u95f4\u6709\u4e00\u5b9a\u7684\u95f4\u8ddd\u3002<\/li>\n\n\n\n<li>\u4e0a\u4e0b\u4e24\u884c\u88ab\u5c45\u4e2d\u663e\u793a\u5728\u9875\u9762\u4e0a\uff0c\u5e76\u4e14\u6bcf\u884c\u7684\u5143\u7d20\u4e4b\u95f4\u548c\u4e0a\u4e0b\u4e24\u884c\u4e4b\u95f4\u90fd\u4fdd\u6301\u4e00\u5b9a\u7684\u95f4\u9694\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u4e2a\u5e03\u5c40\u975e\u5e38\u9002\u5408\u9700\u8981\u4e24\u4e2a\u884c\u5143\u7d20\u89c6\u89c9\u4e0a\u88ab\u201c\u5939\u4f4f\u201d\u7684\u6548\u679c\uff0c\u4e14\u4f7f\u7528\u4e86 Flexbox \u4f7f\u5f97\u5e03\u5c40\u5728\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u4e0b\u975e\u5e38\u7075\u6d3b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 HTML \u4e2d\u4f7f\u7528&nbsp;Flexbox&nbsp;\u5e03\u5c40\u5b9e\u73b0\u201c\u53cc\u884c\u5939\u6279\u6548\u679c&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/11\/20\/html%e4%b8%ad%e4%bd%bf%e7%94%a8flex%e5%b8%83%e5%b1%80%e5%ae%9e%e7%8e%b0%e5%8f%8c%e8%a1%8c%e5%a4%b9%e6%89%b9%e6%95%88%e6%9e%9c\/\">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":[5],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-html-xhtml"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/16","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=16"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":17,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/16\/revisions\/17"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}