{"id":1570,"date":"2024-11-10T13:40:20","date_gmt":"2024-11-10T05:40:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1570\/"},"modified":"2024-11-10T13:40:20","modified_gmt":"2024-11-10T05:40:20","slug":"flex-%e5%b8%83%e5%b1%80%e4%b8%ad-overflow-%e5%a4%b1%e6%95%88%e8%af%a5%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1570\/","title":{"rendered":"Flex \u5e03\u5c40\u4e2d overflow \u5931\u6548\u8be5\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173047099268466.jpg\" class=\"aligncenter\" title=\"Flex \u5e03\u5c40\u4e2d overflow \u5931\u6548\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Flex \u5e03\u5c40\u4e2d overflow \u5931\u6548\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>flex \u5e03\u5c40\u4e2d  \u5931\u6548\u7684\u89e3\u51b3<\/strong><\/p>\n<p>\u5728 Flex \u5e03\u5c40\u4e2d\uff0coverflow \u5c5e\u6027\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\u53ef\u80fd\u5931\u6548\u3002\u4e3a\u4e86\u89e3\u91ca\u8fd9\u4e00\u70b9\uff0c\u8ba9\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a div \u7684\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;div class=\"wrapper\"&gt;\n  &lt;div class=\"div1\"&gt;&lt;\/div&gt;\n  &lt;div class=\"div2\" style=\"flex-grow: 1\"&gt;&lt;\/div&gt;\n&lt;\/div&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>wrapper div \u4f7f\u7528 Flex \u5e03\u5c40\uff0c\u65b9\u5411\u4e3a\u5782\u76f4\u3002div1 \u548c div2 \u662f\u4e24\u4e2a\u5b50\u5143\u7d20\u3002\u6211\u4eec\u5e0c\u671b div2 \u7684\u5185\u5bb9\u6ea2\u51fa\u65f6\u51fa\u73b0\u6eda\u52a8\u6761\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5982\u679c\u5728 div1 \u4e0a\u8bbe\u7f6e overflow-scroll\uff0c\u5219\u8be5\u5c5e\u6027\u53ef\u80fd\u4f1a\u5931\u6548\u3002\u8fd9\u662f\u56e0\u4e3a\uff1a<\/p>\n<ul>\n<li><strong>overflow \u51fa\u73b0\u7684\u6761\u4ef6\u4e4b\u4e00\u662f\u5185\u5bb9\u8d85\u51fa\u5bb9\u5668\u3002<\/strong><\/li>\n<li>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0cdiv1 \u7684\u5185\u5bb9\u4e0d\u8d85\u51fa\u5bb9\u5668\uff08\u5373 wrapper\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u786e\u4fdd div2 \u7684\u5185\u5bb9\u8d85\u51fa wrapper \u5bb9\u5668\uff1a<\/p>\n<ul>\n<li>\u8bbe\u7f6e wrapper \u7684\u9ad8\u5ea6\u9650\u5236\uff0c\u4f8b\u5982\u4f7f\u7528 height \u6216 max-height\u3002<\/li>\n<li>\u5728 div2 \u4e0a\u8bbe\u7f6e flex-grow\uff0c\u4f7f\u5176\u81ea\u52a8\u6269\u5c55\u4ee5\u586b\u5145\u53ef\u7528\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<p><strong>\u5177\u4f53\u8bbe\u7f6e\uff1a<\/strong><\/p>\n<pre>.wrapper {\n  height: 500px;  \/\/ \u53ef\u6839\u636e\u9700\u8981\u8c03\u6574\n  display: flex;\n  flex-direction: column;\n}\n\n.div2 {\n  flex-grow: 1;\n  overflow-y: scroll;  \/\/ \u5728\u8fd9\u91cc\u8bbe\u7f6e\u6eda\u52a8\u6761\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u8bbe\u7f6e\uff0cdiv2 \u5c06\u6269\u5c55\u4ee5\u586b\u5145 wrapper \u7684\u53ef\u7528\u7a7a\u95f4\uff0c\u5e76\u4f1a\u5728\u5185\u5bb9\u6ea2\u51fa\u65f6\u51fa\u73b0\u6eda\u52a8\u6761\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fFlex \u5e03\u5c40\u4e2d  \u5931\u6548\u8be5\u5982\u4f55\u89e3\u51b3\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>flex \u5e03\u5c40\u4e2d \u5931\u6548\u7684\u89e3\u51b3 \u5728 Flex \u5e03\u5c40\u4e2d\uff0coverflow \u5c5e\u6027\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\u53ef\u80fd\u5931\u6548\u3002\u4e3a\u4e86\u89e3\u91ca\u8fd9\u4e00\u70b9\uff0c\u8ba9\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a div \u7684\u793a\u4f8b\uff1a &lt;div class=&#8221;wrapper&#8221;&gt; &lt;div class=&#8221;div1&#8243;&gt;&lt;\/div&gt; &lt;div class=&#8221;div2&#8243; style=&#8221;flex-grow: 1&#8243;&gt;&lt;\/div&gt; &lt;\/div&gt; \u767b\u5f55\u540e\u590d\u5236 wrapper div \u4f7f\u7528 Flex \u5e03\u5c40\uff0c\u65b9\u5411\u4e3a\u5782\u76f4\u3002div1 \u548c div2 \u662f\u4e24\u4e2a\u5b50\u5143\u7d20\u3002\u6211\u4eec\u5e0c\u671b div2 \u7684\u5185\u5bb9\u6ea2\u51fa\u65f6\u51fa\u73b0\u6eda\u52a8\u6761\u3002 \u7136\u800c\uff0c\u5982\u679c\u5728 div1 \u4e0a\u8bbe\u7f6e overflow-scroll\uff0c\u5219\u8be5\u5c5e\u6027\u53ef\u80fd\u4f1a\u5931\u6548\u3002\u8fd9\u662f\u56e0\u4e3a\uff1a overflow \u51fa\u73b0\u7684\u6761\u4ef6\u4e4b\u4e00\u662f\u5185\u5bb9\u8d85\u51fa\u5bb9\u5668\u3002 \u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0cdiv1 \u7684\u5185\u5bb9\u4e0d\u8d85\u51fa\u5bb9\u5668\uff08\u5373 wrapper\uff09\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u786e\u4fdd div2 \u7684\u5185\u5bb9\u8d85\u51fa wrapper \u5bb9\u5668\uff1a \u8bbe\u7f6e wrapper \u7684\u9ad8\u5ea6\u9650\u5236\uff0c\u4f8b\u5982\u4f7f\u7528 height \u6216 max-height\u3002 \u5728 div2 \u4e0a\u8bbe\u7f6e flex-grow\uff0c\u4f7f\u5176\u81ea\u52a8\u6269\u5c55\u4ee5\u586b\u5145\u53ef\u7528\u7a7a\u95f4\u3002 \u5177\u4f53\u8bbe\u7f6e\uff1a [&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-1570","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1570","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=1570"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1570\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}