{"id":9541,"date":"2020-10-06T13:21:29","date_gmt":"2020-10-06T05:21:29","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9541"},"modified":"2020-12-25T23:42:18","modified_gmt":"2020-12-25T15:42:18","slug":"css-flex-0-1-none","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2020\/10\/css-flex-0-1-none\/","title":{"rendered":"flex:0 flex:1 flex:none flex:auto\u5e94\u8be5\u5728\u4ec0\u4e48\u573a\u666f\u4e0b\u4f7f\u7528\uff1f"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9541\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9541<\/a><br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202010-flex-0-1-none.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/flex-0-1-none-cover.png\" width=\"484\" height=\"303\" class=\"alignright thumb clip size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u63a8\u8350\u4f7f\u7528flex\u7f29\u5199\u8bed\u6cd5<\/h3>\n<p>CSS\u5b98\u65b9\u6587\u6863\u660e\u786e\u63a8\u8350flex\u5c5e\u6027\u4f7f\u7528\u7f29\u5199\u8bed\u6cd5\uff0c\u63cf\u8ff0\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<blockquote><p>Authors are encouraged to control flexibility using the flex shorthand rather than with its longhand properties directly, as the shorthand correctly resets any unspecified components to accommodate common uses.<\/p><\/blockquote>\n<p>\u5927\u81f4\u610f\u601d\u662f\uff0c\u5efa\u8bae\u4f7f\u7528\u5355\u503c\u7f29\u5199\uff0c\u800c\u4e0d\u662f\u5b8c\u6574\u76843\u4e2a\u5c5e\u6027\u503c\uff0c\u56e0\u4e3a\u5355\u503c\u5c5e\u6027\u6240\u5bf9\u5e94\u7684flex\u8ba1\u7b97\u503c\u6839\u636e\u5f00\u53d1\u8005\u65e5\u5e38\u6700\u5e38\u7528\u7684\u4f7f\u7528\u8fdb\u884c\u4e86\u4f18\u5316\u3002<\/p>\n<p>\u8fd9\u53e5\u8bdd\u5f88\u591a\u4eba\u5e76\u4e0d\u77e5\u9053\u4ec0\u4e48\u610f\u601d\uff0c\u8fd9\u4e2a\u8bf4\u6765\u8bdd\u957f\uff0c\u60f3\u60f3\u8fd8\u662f\u8bb2\u4e00\u4e0b\u5427\u3002<\/p>\n<p><code>flex<\/code>\u5c5e\u6027\u662f<code>flex-grow<\/code>\uff0c<code>flex-shrink<\/code>\u548c<code>flex-basis<\/code>\u8fd93\u4e2aCSS\u5c5e\u6027\u7684\u7f29\u5199\uff0c\u5982\u679c\u4e0d\u6e05\u695a\uff0c\u53ef\u4ee5\u53c2\u89c1\u6211\u4e4b\u524d\u8fd9\u7bc7\u53e3\u7891\u70ed\u6587\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/12\/css-flex-deep\/\">CSS flex\u5c5e\u6027\u6df1\u5165\u7406\u89e3<\/a>\u201d\u3002<\/p>\n<p>\u6309\u7167\u4ee5\u5f80\u7684\u7ecf\u9a8c\uff0c<code>flex<\/code>\u5c5e\u6027\u53ea\u6709\u4e00\u4e2a\u503c\u7684\u65f6\u5019\uff0c\u53e6\u5916\u7f3a\u7701\u7684\u503c\u5e94\u8be5\u4f7f\u7528\u9ed8\u8ba4\u503c\u624d\u5bf9\uff0c\u4f46\u662f<code>flex<\/code>\u5c5e\u6027\u5e76\u4e0d\u662f\u8fd9\u6837\u7684\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5bf9\u6bd4CSS <code>border<\/code>\u5c5e\u6027\u3002<\/p>\n<p>CSS <code>border<\/code>\u5c5e\u6027\u662f<code>border-width<\/code>\uff0c<code>border-style<\/code>\u548c<code>border-color<\/code>\u8fd93\u4e2aCSS\u5c5e\u6027\u7684\u7f29\u5199\uff0c\u5f53<code>border<\/code>\u5c5e\u6027\u8bbe\u7f6e\u4e861\u4e2a\u503c\u62162\u4e2a\u503c\u7684\u65f6\u5019\uff0c\u5269\u4e0b\u7684\u5c5e\u6027\u503c\u4e00\u5b9a\u662f\u9ed8\u8ba4\u503c\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><code>border:2px<\/code>\u7b49\u540c\u4e8e<code>border:2px none currentColor<\/code>\uff0c\u4e5f\u5c31\u662f\u6b64\u65f6<code>border-style<\/code>\u662f\u9ed8\u8ba4\u503c<code>none<\/code>\uff0c<code>border-color<\/code>\u7684\u8ba1\u7b97\u503c\u662f\u5f53\u524d\u7684\u8272\u503c\uff1b<\/li>\n<li><code>border:#fff<\/code>\u7b49\u540c\u4e8e<code>border:medium none #fff<\/code>\uff0c\u4e5f\u5c31\u662f\u6b64\u65f6<code>border-width<\/code>\u662f\u9ed8\u8ba4\u503c<code>medium<\/code>\uff1b<\/li>\n<li><code>border:solid<\/code>\u7b49\u540c\u4e8e<code>border:medium solid currentColor<\/code>\u3002<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u5f97\u5230<code>flex-basis<\/code>\u9ed8\u8ba4\u503c\u662f<code>auto<\/code>\uff0c<code>flex-grow<\/code>\u9ed8\u8ba4\u503c\u662f<code>0<\/code>\uff0c<code>flex-shrink<\/code>\u9ed8\u8ba4\u503c\u662f<code>1<\/code>\u3002<\/p>\n<pre>console.log(getComputedStyle(document.body).flexGrow);\r\nconsole.log(getComputedStyle(document.body).flexShrink);\r\nconsole.log(getComputedStyle(document.body).flexBasis);<\/pre>\n<p>\u5b9e\u9645\u8fd0\u884c\u6548\u679c\u5982\u4e0b\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202009\/6-39-insert_flex-initial2.png\" loading=\"lazy\" alt=\"Chrome\u548cFirefox\u6d4f\u89c8\u5668\u83b7\u53d6\u7684flex\u5b50\u5c5e\u6027\u7684\u9ed8\u8ba4\u503c\u793a\u610f\"><\/p>\n<p>\u7136\u540e\u518d\u770b\u4e0b<code>flex<\/code>\u7f29\u5199\u5c5e\u6027\u7684\u8ba1\u7b97\u503c\uff0c\u5c31\u4f1a\u53d1\u73b0\u4e0d\u4e00\u6837\u7684\u4e8b\u60c5\uff1a<\/p>\n<ul>\n<li><code>flex:1<\/code>\u7b49\u540c\u4e8e<code>flex:1 1 0%<\/code>\uff0c<code>flex:1 2<\/code>\u7b49\u540c\u4e8e<code>flex:1 2 0%<\/code>\uff0c\u5373<code>flex-basis<\/code>\u4f7f\u7528\u7684\u4e0d\u662f\u9ed8\u8ba4\u503c<code>auto<\/code>\uff0c\u800c\u662f\u4f7f\u7528\u7684<code>0%<\/code>\uff1b<\/li>\n<li><code>flex:100px<\/code>\u7b49\u540c\u4e8e<code>flex:1 1 100px<\/code>\uff0c\u5373<code>flex-grow<\/code>\u4f7f\u7528\u7684\u4e0d\u662f\u9ed8\u8ba4\u503c<code>0<\/code>\uff0c\u800c\u662f\u4f7f\u7528\u7684<code>1<\/code>\uff1b<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u662f\u4e0a\u9762\u63d0\u5230\u7684<code>flex<\/code>\u5c5e\u6027\u7ad9\u5728\u5b9e\u7528\u4e3b\u4e49\u7684\u89d2\u5ea6\u5bf9\u7f29\u5199\u5c5e\u6027\u7684\u8ba1\u7b97\u503c\u8fdb\u884c\u4e86\u4f18\u5316\u3002<\/p>\n<p>\u7136\u540e\uff0c\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u539f\u56e0\uff0cflex\u5c5e\u6027\u7684\u957f\u8bed\u6cd5\u9700\u8981\u7406\u89e3\u6df1\u523b\uff0c\u53cd\u590d\u4f7f\u7528\u624d\u80fd\u9a7e\u9a6d\uff0c\u95e8\u69db\u6bd4\u8f83\u597d\uff0c\u56e0\u6b64\uff0c\u5b9e\u9645\u5f00\u53d1\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5efa\u8bae\u4f7f\u7528flex\u7f29\u5199\u3002<\/p>\n<p>\u5e38\u89c1\u7684flex\u7f29\u5199\u6709\u4e0b\u9762\u8fd9\u51e0\u4e2a\uff0c<code>flex:0<\/code>\u3001<code>flex:1<\/code>\u3001<code>flex:none<\/code>\u3001<code>flex:auto<\/code>\uff0c\u90a3\u5404\u4e2aCSS\u58f0\u660e\u5e94\u8be5\u5728\u4ec0\u4e48\u573a\u666f\u4e0b\u4f7f\u7528\u624d\u6b63\u786e\u5462\uff1f<\/p>\n<p><span class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4f53\u9a8c\u7cdf\u7cd5\u7684\u5783\u573e\u76d7\u7248\u7f51\u7ad9\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u539f\u6587\u83b7\u5f97\u5f88\u597d\u7684\u4f53\u9a8c\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=9541\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/span><\/p>\n<h3>\u4e8c\u3001\u4f7f\u7528flex\u7f29\u5199\u8bed\u6cd5\u573a\u666f<\/h3>\n<p>\u4e0b\u8868\u5c55\u793a\u4e86\u5e38\u89c1\u7684<code>flex<\/code>\u5c5e\u6027\u5355\u503c\u8bed\u6cd5\u5bf9\u5e94\u7684<code>flex<\/code>\u8ba1\u7b97\u503c\uff0c\u6db5\u76d6\u4e86\u7edd\u5927\u591a\u6570\u7684<code>flex<\/code>\u5c5e\u6027\u7684\u4f7f\u7528\u573a\u666f\u3002<\/p>\n<table border=\"0\" class=\"params_table\" cellspacing=\"1\">\n<caption><small>flex\u5355\u503c\u8bed\u6cd5\u5bf9\u5e94\u7684\u8ba1\u7b97\u503c<\/small><\/caption>\n<thead>\n<tr>\n<th>\u5355\u503c\u8bed\u6cd5<\/th>\n<th>\u7b49\u540c\u4e8e<\/th>\n<th>\u5907\u6ce8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr align=\"left\">\n<td>flex: initial<\/td>\n<td>flex: 0 1 auto<\/td>\n<td>\u521d\u59cb\u503c\uff0c\u5e38\u7528<\/td>\n<\/tr>\n<tr align=\"left\">\n<td>flex: 0<\/td>\n<td>flex: 0 1 0%<\/td>\n<td>\u9002\u7528\u573a\u666f\u5c11<\/td>\n<\/tr>\n<tr align=\"left\">\n<td>flex: none<\/td>\n<td>flex: 0 0 auto<\/td>\n<td>\u63a8\u8350<\/td>\n<\/tr>\n<tr align=\"left\">\n<td>flex: 1<\/td>\n<td>flex: 1 1 0%<\/td>\n<td>\u63a8\u8350<\/td>\n<\/tr>\n<tr align=\"left\">\n<td>flex: auto<\/td>\n<td>flex: 1 1 auto<\/td>\n<td>\u9002\u7528\u573a\u666f\u5c11<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1. flex:initial\u57fa\u672c\u8868\u73b0\u548c\u9002\u7528\u573a\u666f<\/h4>\n<p><code>flex:initial<\/code>\u7b49\u540c\u4e8e\u8bbe\u7f6e<code>flex: 0 1 auto<\/code>\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3aflex\u5c5e\u6027\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u8be5\u9ed8\u8ba4\u503c\u56fe\u5f62\u793a\u610f\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202005\/6-39_flex-initial.png\" loading=\"lazy\" width=\"283\" height=\"143\" alt=\"flex\u5c5e\u6027\u521d\u59cb\u503c\u5206\u89e3\u793a\u610f\"><\/p>\n<p>\u5176\u884c\u4e3a\u8868\u73b0\u6587\u5b57\u63cf\u8ff0\u4e3a\uff1a<\/p>\n<blockquote><p>flex\u5bb9\u5668\u6709\u5269\u4f59\u7a7a\u95f4\u65f6\u5c3a\u5bf8\u4e0d\u4f1a\u589e\u957f\uff08flex-grow:0\uff09\uff0cflex\u5bb9\u5668\u5c3a\u5bf8\u4e0d\u8db3\u65f6\u5c3a\u5bf8\u4f1a\u6536\u7f29\u53d8\u5c0f\uff08flex-shrink:1\uff09\uff0c\u5c3a\u5bf8\u81ea\u9002\u5e94\u4e8e\u5185\u5bb9\uff08flex-basis:auto\uff09\uff08\u884c\u4e3a\u7c7b\u4f3cfit-content\uff09\u3002<\/p><\/blockquote>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u7ed9flex\u5bb9\u5668\u8bbe\u7f6e\u6df1\u7ea2\u8272\u7684\u865a\u7ebf\u6846\uff0c\u5982\u679c\u6b64\u65f6flex\u5b50\u9879\uff08\u8bbe\u7f6e\u6df1\u5929\u84dd\u8272\u8f6e\u5ed3\uff09\u7684\u5185\u5bb9\u90fd\u6bd4\u8f83\u5c11\uff0c\u5c31\u4f1a\u6709\u5982\u4e0b\u56fe\u6240\u793a\u7684\u6548\u679c\uff0c\u5269\u4f59\u7a7a\u95f4\u4f9d\u7136\u4fdd\u7559\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202005\/6-40_flex-initial-less.png\" loading=\"lazy\" width=\"331\" height=\"95\" alt=\"flex\u5b50\u9879\u5185\u5bb9\u8f83\u5c11\u65f6\u5019\u7684\u5c3a\u5bf8\u8868\u73b0\"><\/p>\n<p>\u76f8\u5173CSS\u4ee3\u7801\u548cHTML\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre name=\"code\" class=\"css\">.container {\r\n    display: flex;\r\n    border: 2px dashed crimson;\r\n}\r\n.container item {\r\n    border: 2px solid deepskyblue;    \r\n}<\/pre>\n<pre name=\"code\" class=\"html\">&lt;div class=\"container\"&gt;\r\n    &lt;item&gt;\u8303\u5f20&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u946b&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u65ed&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u5e05&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u54e5&lt;\/item&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u5982\u679c\u5b50\u9879\u5185\u5bb9\u5f88\u591a\uff0c\u7531\u4e8e<code>flex-shrink:1<\/code>\uff0c\u56e0\u6b64\uff0c\u4f1a\u7f29\u5c0f\uff0c\u8868\u73b0\u6548\u679c\u5c31\u662f\u6587\u5b57\u6362\u884c\uff0c\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202005\/6-41_flex-initial-more.png\" loading=\"lazy\" width=\"359\" height=\"183\" alt=\"flex\u5b50\u9879\u5185\u5bb9\u8f83\u591a\u65f6\u5019\u7684\u5c3a\u5bf8\u8868\u73b0\"><\/p>\n<p><p><code>'initial'<\/code>\u662fCSS\u4e2d\u7684\u4e00\u4e2a\u5168\u5c40\u5173\u952e\u5b57\uff0c\u8868\u793aCSS\u5c5e\u6027\u7684\u521d\u59cb\u503c\uff0c\u901a\u5e38\u7528\u6765\u8fd8\u539f\u5df2\u7ecf\u8bbe\u7f6e\u7684CSS\u5c5e\u6027\u3002\u56e0\u6b64\u65e5\u5e38\u5f00\u53d1\u4e0d\u4f1a\u4e13\u95e8\u8bbe\u7f6e<code>flex:initial<\/code>\u58f0\u660e\uff0c\u4f46\u662f\u4e0d\u8bbe\u7f6e\u5e76\u4e0d\u662f\u8bf4<code>flex<\/code>\u9ed8\u8ba4\u5c5e\u6027\u503c\u7528\u7684\u4e0d\u591a\u3002<\/p>\n<h5>flex:initial\u9002\u7528\u573a\u666f<\/h5>\n<p><code>flex:initial<\/code>\u58f0\u660e\u9002\u7528\u4e8e\u4e0b\u56fe\u6240\u793a\u7684\u5e03\u5c40\u6548\u679c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-45-insert_flex-initial-situable2.png\" loading=\"lazy\" width=\"416\" height=\"164\" alt=\"\u9002\u5408flex:initial\u58f0\u660e\u7684\u5e03\u5c40\u8f6e\u5ed3\u56fe\u793a\u610f\"><\/p>\n<p>\u4e0a\u56fe\u6240\u793a\u7684\u5e03\u5c40\u6548\u679c\u5e38\u89c1\u4e8e\u6309\u94ae\u3001\u6807\u9898\u3001\u5c0f\u56fe\u6807\u7b49\u5c0f\u90e8\u4ef6\u7684\u6392\u7248\u5e03\u5c40\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u5c0f\u90e8\u4ef6\u7684\u5bbd\u5ea6\u90fd\u4e0d\u4f1a\u5f88\u5bbd\uff0c\u6c34\u5e73\u4f4d\u7f6e\u7684\u63a7\u5236\u591a\u4f7f\u7528<code>justify-content<\/code>\u548c<code>margin-left:auto\/margin-right:auto<\/code>\u5b9e\u73b0\u3002<\/p>\n<p>\u9664\u4e86\u4e0a\u56fe\u6240\u793a\u7684\u5e03\u5c40\u6548\u679c\u5916\uff0c<code>flex:initial<\/code>\u58f0\u660e\u8fd8\u9002\u7528\u4e8e\u4e00\u4fa7\u5185\u5bb9\u5bbd\u5ea6\u56fa\u5b9a\uff0c\u53e6\u5916\u4e00\u4fa7\u5185\u5bb9\u5bbd\u5ea6\u4efb\u610f\u7684\u4e24\u680f\u81ea\u9002\u5e94\u5e03\u5c40\u573a\u666f\uff0c\u5e03\u5c40\u8f6e\u5ed3\u5982\u56fe\u4e0b\u56fe\u6240\u793a\uff08\u70b9\u70b9\u70b9\u8868\u793a\u6587\u672c\u5185\u5bb9\uff09\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-45-insert_flex-initial-suitable2.png\" loading=\"lazy\" width=\"415\" height=\"110\" alt=\"\u9002\u5408flex:initial\u58f0\u660e\u7684\u4e24\u680f\u81ea\u9002\u5e94\u5e03\u5c40\u8f6e\u5ed3\u56fe\u793a\u610f\"><\/p>\n<p>\u6b64\u65f6\uff0c\u65e0\u9700\u4efb\u4f55\u5176\u4ed6Flex\u5e03\u5c40\u76f8\u5173\u7684CSS\u8bbe\u7f6e\uff0c\u53ea\u9700\u8981\u5bb9\u5668\u5143\u7d20\u8bbe\u7f6e<code>display:flex<\/code>\u5373\u53ef\u3002<\/p>\n<p>\u603b\u7ed3\u4e0b\u5c31\u662f\u90a3\u4e9b\u5e0c\u671b\u5143\u7d20\u5c3a\u5bf8\u6536\u7f29\uff0c\u540c\u65f6\u5143\u7d20\u5185\u5bb9\u4e07\u4e00\u8f83\u591a\u53c8\u80fd\u81ea\u52a8\u6362\u884c\u7684\u573a\u666f\u53ef\u4ee5\u4e0d\u505a\u4efb\u4f55<code>flex<\/code>\u5c5e\u6027\u8bbe\u7f6e\u3002<\/p>\n<h4>2. flex:0\u548cflex:none\u7684\u533a\u522b\u548c\u5404\u81ea\u9002\u7528\u573a\u666f<\/h4>\n<p><code>flex:0<\/code>\u7b49\u540c\u4e8e\u8bbe\u7f6e<code>flex: 0 1 0%<\/code>\uff0c<code>flex:none<\/code>\u7b49\u540c\u4e8e\u8bbe\u7f6e<code>flex: 0 0 auto<\/code>\u3002<\/p>\n<p>\u8fd9\u4e24\u4e2a\u503c\u7684\u56fe\u5f62\u793a\u610f\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/flex-0-none.png\" loading=\"lazy\" width=\"277\" height=\"235\" alt=\"flex:0\u548cflex:none\u5206\u89e3\u793a\u610f\"><\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li><code>flex:0 1 0%<\/code>\u8868\u793a<code>flex-grow<\/code>\u662f0\uff0c<code>flex-shrink<\/code>\u662f1\uff0c\u56e0\u6b64\u5143\u7d20\u5c3a\u5bf8\u4f1a\u6536\u7f29\u4f46\u4e0d\u4f1a\u6269\u5c55\uff0c\u5728\u52a0\u4e0a<code>flex-basis:0%<\/code>\u8868\u793a\u5efa\u8bae\u652f\u6301\u662f0\uff0c\u56e0\u6b64\uff0c\u8bbe\u7f6e<code>flex:0<\/code>\u7684\u5143\u7d20\u7684\u6700\u7ec8\u5c3a\u5bf8\u8868\u73b0\u4e3a\u6700\u5c0f\u5185\u5bb9\u5bbd\u5ea6\uff1b<\/li>\n<li><code>flex:0 0 auto<\/code>\u8868\u793a\u5143\u7d20\u5c3a\u5bf8\u4e0d\u4f1a\u6536\u7f29\u4e5f\u4e0d\u4f1a\u6269\u5c55\uff0c\u518d\u52a0\u4e0a<code>flex-basis:auto<\/code>\u8868\u793a\u56fa\u5b9a\u5c3a\u5bf8\u7531\u5185\u5bb9\u51b3\u5b9a\uff0c\u7531\u4e8e\u5143\u7d20\u4e0d\u5177\u6709\u5f39\u6027\uff0c\u56e0\u6b64\uff0c\u5143\u7d20\u5185\u7684\u5185\u5bb9\u4e0d\u4f1a\u6362\u884c\uff0c\u6700\u7ec8\u5c3a\u5bf8\u901a\u5e38\u8868\u73b0\u4e3a\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u3002<\/li>\n<\/ul>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u8bbe\u7f6e\u6bcf\u4e2aflex\u5b50\u9879\u6709\u8db3\u591f\u591a\u7684\u5185\u5bb9\uff0cHTML\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;h4&gt;flex:0&lt;\/h4&gt;\r\n&lt;div class=\"container flex-0\"&gt;\r\n    &lt;item&gt;\u8303\u5f20\u8303\u5f20\u8303\u5f20&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u946b\u8303\u946b\u8303\u946b&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u65ed\u8303\u65ed\u8303\u65ed&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u5e05\u8303\u5e05\u8303\u5e05&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u54e5\u8303\u54e5\u8303\u54e5&lt;\/item&gt;\r\n&lt;\/div&gt;\r\n&lt;h4&gt;flex:none&lt;\/h4&gt;\r\n&lt;div class=\"container flex-none\"&gt;\r\n    &lt;item&gt;\u8303\u5f20\u8303\u5f20\u8303\u5f20&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u946b\u8303\u946b\u8303\u946b&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u65ed\u8303\u65ed\u8303\u65ed&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u5e05\u8303\u5e05\u8303\u5e05&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u54e5\u8303\u54e5\u8303\u54e5&lt;\/item&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u7136\u540e\u5bf9flex\u5b50\u9879\u5206\u522b\u8bbe\u7f6e<code>flex:0<\/code>\u548c<code>flex:none<\/code>\uff0cCSS\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>.container {\r\n    display: flex;\r\n}\r\n.flex-0 item {\r\n    flex: 0;\r\n}\r\n.flex-none item {\r\n    flex: none;\r\n}<\/pre>\n<p>\u7ed3\u679c\u5982\u56fe\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-45_flex-0-none.png\" loading=\"lazy\" width=\"445\" height=\"231\" alt=\"flex:0\u548cflex:none\u7684\u5e03\u5c40\u6548\u679c\u793a\u610f\"><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u5e94\u7528\u4e86<code>flex:0<\/code>\u7684\u5143\u7d20\u5168\u90e8\u9ad8\u9ad8\u8038\u8d77\uff0c\u4e00\u67f1\u64ce\u5929\uff0c\u8868\u73b0\u4e3a\u6700\u5c0f\u5185\u5bb9\u5bbd\u5ea6\uff1b\u800c\u5e94\u7528\u4e86<code>flex:none<\/code>\u7684\u5143\u7d20\u5219\u65e0\u89c6\u5bb9\u5668\u7684\u5c3a\u5bf8\u9650\u5236\uff0c\u76f4\u63a5\u6ea2\u51fa\u5bb9\u5668\uff0c\u6ca1\u6709\u6362\u884c\uff0c\u8868\u73b0\u4e3a\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u3002<\/p>\n<h5>\u9002\u5408\u4f7f\u7528flex:0\u7684\u573a\u666f<\/h5>\n<p>\u7531\u4e8e\u5e94\u7528\u4e86<code>flex:0<\/code>\u7684\u5143\u7d20\u8868\u73b0\u4e3a\u6700\u5c0f\u5185\u5bb9\u5bbd\u5ea6\uff0c\u56e0\u6b64\uff0c\u9002\u5408\u4f7f\u7528<code>flex:0<\/code>\u7684\u573a\u666f\u5e76\u4e0d\u591a\uff0c\u9664\u975e\u5143\u7d20\u5185\u5bb9\u7684\u4e3b\u4f53\u662f\u66ff\u6362\u5143\u7d20\uff0c\u6b64\u65f6\u6587\u5b57\u5185\u5bb9\u5c31\u4f1a\u5e87\u62a4\u5728\u66ff\u6362\u5143\u7d20\u7684\u5bbd\u5ea6\u4e0b\u4ece\u800c\u4e0d\u4f1a\u51fa\u73b0\u201c\u4e00\u67f1\u64ce\u5929\u201d\u7684\u6392\u7248\u6548\u679c\u3002<\/p>\n<p>\u8be5\u9002\u7528\u573a\u666f\u7684\u5e03\u5c40\u793a\u610f\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-49-insert_flex-0-suitable2.png\" loading=\"lazy\" width=\"416\" height=\"209\" alt=\"\u9002\u7528\u4e8eflex:0\u7684\u5e03\u5c40\u8f6e\u5ed3\u793a\u610f\u56fe\"><\/p>\n<p>\u5176\u4e2d\u4e0a\u56fe\u5de6\u4fa7\u90e8\u5206\u7684\u77e9\u5f62\u8868\u793a\u4e00\u4e2a\u56fe\u50cf\uff0c\u56fe\u50cf\u4e0b\u65b9\u4f1a\u6709\u6587\u5b57\u5185\u5bb9\u4e0d\u5b9a\u7684\u63cf\u8ff0\u4fe1\u606f\uff0c\u6b64\u65f6\uff0c\u5de6\u4fa7\u5185\u5bb9\u5c31\u9002\u5408\u8bbe\u7f6e<code>flex:0<\/code>\uff0c\u8fd9\u6837\uff0c\u65e0\u8bba\u6587\u5b57\u7684\u5185\u5bb9\u5982\u4f55\u8bbe\u7f6e\uff0c\u5de6\u4fa7\u5185\u5bb9\u7684\u5bbd\u5ea6\u90fd\u662f\u56fe\u50cf\u7684\u5bbd\u5ea6\u3002<\/p>\n<h5>\u9002\u5408\u4f7f\u7528flex:none\u7684\u573a\u666f<\/h5>\n<p>\u5f53flex\u5b50\u9879\u7684\u5bbd\u5ea6\u5c31\u662f\u5185\u5bb9\u7684\u5bbd\u5ea6\uff0c\u4e14\u5185\u5bb9\u6c38\u8fdc\u4e0d\u4f1a\u6362\u884c\uff0c\u5219\u9002\u5408\u4f7f\u7528<code>flex:none<\/code>\uff0c\u8fd9\u4e2a\u573a\u666f\u6bd4<code>flex:0<\/code>\u9002\u7528\u7684\u573a\u666f\u8981\u66f4\u5e38\u89c1\u3002<\/p>\n<p>\u4f8b\u5982\u5217\u8868\u53f3\u4fa7\u7ecf\u5e38\u4f1a\u6709\u4e00\u4e2a\u64cd\u4f5c\u6309\u94ae\uff0c\u5bf9\u4e8e\u6309\u94ae\u5143\u7d20\u800c\u8a00\uff0c\u91cc\u9762\u7684\u6587\u5b57\u5185\u5bb9\u4e00\u5b9a\u662f\u4e0d\u80fd\u6362\u884c\u7684\uff0c\u6b64\u65f6\uff0c\u5c31\u975e\u5e38\u9002\u5408\u8bbe\u7f6e<code>flex:none<\/code>\uff0c\u4f8b\u5982\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u793a\u610f\u4e86\u6309\u94ae\u4f7f\u7528\u4e86<code>flex:none<\/code>\u4e4b\u540e\u7684\u5e03\u5c40\u53d8\u5316\uff0cHTML\u548cCSS\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;div class=\"item\"&gt;\r\n    &lt;img src=\"1.jpg\"&gt;\r\n    &lt;p&gt;\u53f3\u4fa7\u6309\u94ae\u6ca1\u6709\u8bbe\u7f6eflex:none\uff0c\u8868\u73b0\u4e3a\u6700\u5c0f\u5185\u5bb9\u5bbd\u5ea6\u3002&lt;\/p&gt;\r\n    &lt;button&gt;\u6309\u94ae&lt;\/button&gt;\r\n&lt;\/div&gt;\r\n&lt;div class=\"item\"&gt;\r\n    &lt;img src=\"1.jpg\"&gt;\r\n    &lt;p&gt;\u53f3\u4fa7\u6309\u94ae\u8bbe\u7f6e\u4e86flex:none\uff0c\u6309\u94ae\u6b63\u5e38\u663e\u793a\u4e86\u3002&lt;\/p&gt;\r\n    &lt;button <span style=\"color:#cd0000;\">class=\"none\"<\/span>&gt;\u6309\u94ae&lt;\/button&gt;\r\n&lt;\/div&gt;<\/pre>\n<pre>.container {\r\n    display: flex;\r\n    padding: .5rem;\r\n    border: 1px solid lightgray;\r\n    background-color: #fff;\r\n}\r\nimg {\r\n    width: 3rem; height: 3rem;\r\n    margin-right: .5rem;\r\n}\r\nbutton {\r\n    align-self: center;\r\n    padding: 5px;\r\n    margin-left: .5rem;\r\n}\r\n<span style=\"color:#cd0000;\">.none {\r\n    flex: none;\r\n}<\/span><\/pre>\n<p>\u4ece\u4ee3\u7801\u53ef\u4ee5\u770b\u51fa\u4e24\u6bb5\u5185\u5bb9\u7684\u552f\u4e00\u533a\u522b\u5c31\u662f\u4e0b\u9762\u7684\u5e03\u5c40\u5bf9\u6309\u94ae\u5143\u7d20\u8bbe\u7f6e\u4e86<code>flex:none<\/code>\uff0c\u7ed3\u679c\u5c31\u6709\u5982\u4e0b\u56fe\u6240\u793a\u7684\u4e0d\u540c\u7684\u5e03\u5c40\u6548\u679c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-50-insert_flex-none-suitable.png\" loading=\"lazy\" width=\"400\" height=\"188\" alt=\"\u9002\u7528\u4e8eflex:none\u7684\u5bf9\u6bd4\u6548\u679c\u793a\u610f\u56fe\"><\/p>\n<p>\u4e0d\u4ec5\u6309\u94ae\u6b63\u5e38\u663e\u793a\u4e86\uff0c\u6574\u4e2a\u5e03\u5c40\u4f1a\u81ea\u52a8\u9002\u914d\u6309\u94ae\u7684\u5c3a\u5bf8\uff0c\u4e5f\u5c31\u662f\u6309\u94ae\u6587\u5b57\u591a\u4e86\uff0c\u4e2d\u95f4\u7684\u6587\u5b57\u5185\u5bb9\u5bbd\u5ea6\u5c31\u4f1a\u81ea\u52a8\u51cf\u5c0f\uff0c\u6574\u4e2a\u5e03\u5c40\u4f9d\u7136\u662f\u5f39\u6027\u7684\u3002<\/p>\n<h4>3. flex:1\u548cflex:auto\u7684\u533a\u522b\u548c\u5404\u81ea\u9002\u7528\u573a\u666f<\/h4>\n<p><code>flex:1<\/code>\u7b49\u540c\u4e8e\u8bbe\u7f6e<code>flex: 1 1 0%<\/code>\uff0c<code>flex:auto<\/code>\u7b49\u540c\u4e8e\u8bbe\u7f6e<code>flex: 1 1 auto<\/code>\u3002<\/p>\n<p>\u8fd9\u4e24\u4e2a\u503c\u7684\u56fe\u5f62\u793a\u610f\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-53-_flex-1-auto-replace.png\" loading=\"lazy\" width=\"276\" height=\"249\" alt=\"flex:1\u548cflex:auto\u5206\u89e3\u793a\u610f\"><\/p>\n<p>\u7ed3\u5408flex\u5c5e\u6027\u503c\u7684\u63cf\u8ff0\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa<code>flex:1<\/code>\u548c<code>flex:auto<\/code>\u7684\u884c\u4e3a\u8868\u73b0\uff1a<\/p>\n<blockquote><p>\u5143\u7d20\u5c3a\u5bf8\u53ef\u4ee5\u5f39\u6027\u589e\u5927\uff0c\u4e5f\u53ef\u4ee5\u5f39\u6027\u53d8\u5c0f\uff0c\u5177\u6709\u5341\u8db3\u7684\u5f39\u6027\uff0c\u4f46\u662f<code>flex:1<\/code>\u5728\u5c3a\u5bf8\u4e0d\u8db3\u65f6\u4f1a\u4f18\u5148\u6700\u5c0f\u5316\u5185\u5bb9\u5c3a\u5bf8\uff0c<code>flex:auto<\/code>\u5728\u5c3a\u5bf8\u4e0d\u8db3\u65f6\u4f1a\u4f18\u5148\u6700\u5927\u5316\u5185\u5bb9\u5c3a\u5bf8\u3002<\/p><\/blockquote>\n<p>\u4e0a\u9762\u7684\u63cf\u8ff0\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u660e\u767d\u662f\u4ec0\u4e48\u610f\u601d\uff0c\u8fd9\u4e00\u6b21\u662f\u4ec5\u4ec5\u8bbe\u7f6e\u7b2c1\u9879\u7684\u6587\u5b57\u5185\u5bb9\u5f88\u591a\uff0cHTML\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;h4&gt;flex:1&lt;\/h4&gt;\r\n&lt;div class=\"container flex-1\"&gt;\r\n    &lt;item&gt;\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u946b&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u65ed&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u5e05&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u54e5&lt;\/item&gt;\r\n&lt;\/div&gt;\r\n&lt;h4&gt;flex:auto&lt;\/h4&gt;\r\n&lt;div class=\"container flex-auto\"&gt;\r\n    &lt;item&gt;\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20\u8303\u5f20&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u946b&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u65ed&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u5e05&lt;\/item&gt;\r\n    &lt;item&gt;\u8303\u54e5&lt;\/item&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u53ef\u4ee5\u770b\u51fa\u4e24\u6bb5HTML\u7ed3\u6784\u548c\u5185\u5bb9\u90fd\u662f\u4e00\u6837\u7684\uff0c\u73b0\u5728\uff0c\u5bf9\u4e0a\u4e0b\u4e24\u7aefHTML\u8bbe\u7f6e\u4e0d\u540c\u7684CSS\u6837\u5f0f\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>.flex-1 item {\r\n    flex: 1;\r\n}\r\n.flex-auto item {\r\n    flex: auto;\r\n}<\/pre>\n<p>\u7ed3\u679c\u5c31\u4f1a\u770b\u5230\u5982\u4e0b\u56fe\u6240\u793a\u7684\u5e03\u5c40\u6548\u679c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-43_flex-1-auto.png\" loading=\"lazy\" width=\"322\" height=\"231\" alt=\"flex:1\u548cflex:auto\u7684\u5bf9\u6bd4\u6548\u679c\u793a\u610f\"><\/p>\n<p>\u4e0a\u56fe\u9c9c\u660e\u5730\u4f53\u73b0\u4e86<code>flex:1<\/code>\u548c<code>flex:auto<\/code>\u7684\u533a\u522b\uff0c\u867d\u7136\u90fd\u662f\u5145\u5206\u5206\u914d\u5bb9\u5668\u7684\u5c3a\u5bf8\uff0c\u4f46\u662f<code>flex:1<\/code>\u7684\u5c3a\u5bf8\u8868\u73b0\u66f4\u4e3a\u5185\u655b\uff08\u4f18\u5148\u727a\u7272\u81ea\u5df1\u7684\u5c3a\u5bf8\uff09\uff0c<code>flex:auto<\/code>\u7684\u5c3a\u5bf8\u8868\u73b0\u5219\u66f4\u4e3a\u9738\u9053\uff08\u4f18\u5148\u6269\u5c55\u81ea\u5df1\u7684\u5c3a\u5bf8\uff09\u3002<\/p>\n<p>\u4ece\u67d0\u79cd\u7a0b\u5ea6\u4e0a\u8bb2\uff0c<code>flex:1<\/code>\u7684\u8868\u73b0\u795e\u4f3c<code>table-layout:fixed<\/code>\uff0c<code>flex:auto<\/code>\u7684\u8868\u73b0\u795e\u4f3c<code>table-layout:auto<\/code>\u3002<\/p>\n<h5>\u9002\u5408\u4f7f\u7528flex:1\u7684\u573a\u666f<\/h5>\n<p>\u5f53\u5e0c\u671b\u5143\u7d20\u5145\u5206\u5229\u7528\u5269\u4f59\u7a7a\u95f4\uff0c\u540c\u65f6\u4e0d\u4f1a\u4fb5\u5360\u5176\u4ed6\u5143\u7d20\u5e94\u6709\u7684\u5bbd\u5ea6\u7684\u65f6\u5019\uff0c\u9002\u5408\u4f7f\u7528<code>flex:1<\/code>\uff0c\u8fd9\u6837\u7684\u573a\u666f\u5728Flex\u5e03\u5c40\u4e2d\u975e\u5e38\u7684\u591a\u3002<\/p>\n<p>\u4f8b\u5982\u6240\u6709\u7684\u7b49\u5206\u5217\u8868\uff0c\u6216\u8005\u7b49\u6bd4\u4f8b\u5217\u8868\u90fd\u9002\u5408\u4f7f\u7528<code>flex:1<\/code>\u6216\u8005\u5176\u4ed6flex\u6570\u503c\uff0c\u9002\u5408\u7684\u5e03\u5c40\u6548\u679c\u8f6e\u5ed3\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-54-insert-_flex-1-suitable.png\" loading=\"lazy\" width=\"416\" height=\"167\" alt=\"flex:1\u9002\u5408\u7528\u5728\u56fa\u5b9a\u6bd4\u4f8b\u7684\u5217\u8868\u4e2d\"><\/p>\n<p>\u4ee5\u53ca\u9002\u7528\u4e8e\u65e0\u89c4\u5f8b\u5e03\u5c40\u4e2d\u52a8\u6001\u5185\u5bb9\u5143\u7d20\uff0c\u6211\u4eec\u4e0d\u59a8\u7ee7\u7eed\u4f7f\u7528<code>flex:none<\/code>\u90a3\u91cc\u6f14\u793a\u7684\u4f8b\u5b50\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u6bb5HTML\u548cCSS\u4ee3\u7801\u4e0b\u7684\u6309\u94ae\u5143\u7d20\u662f\u6362\u884c\u663e\u793a\u7684\uff08\u5c31\u662f\u524d\u9762\u51fa\u73b0\u8fc7\u7684\u6309\u94ae\u4e0d\u6362\u884c\u7684\u4f8b\u5b50\u7684HTML\u4ee3\u7801\uff09\u3002<\/p>\n<pre>&lt;div class=\"item\"&gt;\r\n    &lt;img src=\"1.jpg\"&gt;\r\n    &lt;p&gt;\u53f3\u4fa7\u6309\u94ae\u6ca1\u6709\u8bbe\u7f6eflex:none\uff0c\u8868\u73b0\u4e3a\u6700\u5c0f\u5185\u5bb9\u5bbd\u5ea6\u3002&lt;\/p&gt;\r\n    &lt;button&gt;\u6309\u94ae&lt;\/button&gt;\r\n&lt;\/div&gt;<\/pre>\n<pre>.container {\r\n    display: flex;\r\n    padding: .5rem;\r\n    border: 1px solid lightgray;\r\n    background-color: #fff;\r\n}\r\nimg {\r\n    width: 3rem; height: 3rem;\r\n    margin-right: .5rem;\r\n}\r\nbutton {\r\n    align-self: center;\r\n    padding: 5px;\r\n    margin-left: .5rem;\r\n}<\/pre>\n<p>\u9664\u4e86\u8bbe\u7f6e<code>&lt;button&gt;<\/code>\u5143\u7d20<code>flex:none<\/code>\u4ee5\u5916\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u8bbe\u7f6e<code>&lt;p&gt;<\/code>\u5143\u7d20<code>flex:1<\/code>\u5b9e\u73b0\u7c7b\u4f3c\u7684\u6548\u679c\u3002<\/p>\n<pre>p {\r\n    flex: 1;\r\n}<\/pre>\n<p>\u7ed3\u679c\u5c31\u6709\u5982\u4e0b\u56fe\u6240\u793a\uff0c<code>&lt;p&gt;<\/code>\u5143\u7d20\u8bbe\u7f6e\u4e86<code>flex:1<\/code>\u4e4b\u540e\uff0c\u6309\u94ae\u5143\u7d20\u6b63\u5e38\u663e\u793a\u4e86\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-56-insert-_flex-1-suitable2.png\" loading=\"lazy\" width=\"400\" height=\"186\" alt=\"\u4e3b\u4f53\u52a8\u6001\u7684\u6587\u672c\u5143\u7d20\u8bbe\u7f6eflex:1\u4e4b\u540e\u7684\u6548\u679c\u5bf9\u6bd4\u793a\u610f\"><\/p>\n<h5>\u9002\u5408\u4f7f\u7528flex:auto\u7684\u573a\u666f<\/h5>\n<p>\u5f53\u5e0c\u671b\u5143\u7d20\u5145\u5206\u5229\u7528\u5269\u4f59\u7a7a\u95f4\uff0c\u4f46\u662f\u5404\u81ea\u7684\u5c3a\u5bf8\u6309\u7167\u5404\u81ea\u5185\u5bb9\u8fdb\u884c\u5206\u914d\u7684\u65f6\u5019\uff0c\u9002\u5408\u4f7f\u7528<code>flex:auto<\/code>\u3002<\/p>\n<p><code>flex:auto<\/code>\u591a\u7528\u4e8e\u5185\u5bb9\u56fa\u5b9a\uff0c\u6216\u8005\u5185\u5bb9\u53ef\u63a7\u7684\u5e03\u5c40\u573a\u666f\uff0c\u4f8b\u5982\u5bfc\u822a\u6570\u91cf\u4e0d\u56fa\u5b9a\uff0c\u6bcf\u4e2a\u5bfc\u822a\u6587\u5b57\u6570\u91cf\u4e5f\u4e0d\u56fa\u5b9a\u7684\u5bfc\u822a\u6548\u679c\u5c31\u9002\u5408\u4f7f\u7528<code>flex:auto<\/code>\u6548\u679c\u6765\u5b9e\u73b0\uff0c\u6211\u505a\u4e86\u4e2a\u5f88\u7b80\u5355\u7684\u793a\u610f\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;nav class=\"flex\"&gt;\r\n  &lt;span&gt;\u9996\u9875&lt;\/span&gt;\r\n  &lt;span&gt;\u6392\u884c\u699c&lt;\/span&gt;\r\n  &lt;span&gt;\u6211\u7684\u8ba2\u5355&lt;\/span&gt;\r\n  &lt;span&gt;\u4e2a\u4eba\u4e2d\u5fc3&lt;\/span&gt;\r\n&lt;\/nav&gt;<\/pre>\n<pre>nav span {\r\n    <strong>flex: auto;<\/strong>\r\n    line-height: 3rem;\r\n    background: #444;\r\n    color: #fff;\r\n    text-align:center;\r\n}\r\nspan + span {\r\n    border-left: 1px solid #eee;\r\n}<\/pre>\n<p>\u6b64\u65f6\u5927\u5bb6\u5c31\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u57fa\u4e8e\u5185\u5bb9\u81ea\u52a8\u5206\u914d\u5bbd\u5ea6\u7684\u81ea\u9002\u5e94\u5bfc\u822a\u6548\u679c\u4e86\uff0c\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u6587\u5b57\u8d8a\u591a\u7684\u5bfc\u822a\u5360\u636e\u7684\u5bbd\u5ea6\u8d8a\u5927\uff0c\u8fd9\u5b8c\u5168\u662f\u6d4f\u89c8\u5668\u81ea\u52a8\u5206\u914d\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/6-57-insert-_flex-auto-suitable.png\" loading=\"lazy\" width=\"414\" height=\"49\" alt=\"flex:auto\u5b9e\u73b0\u7684\u57fa\u4e8e\u5185\u5bb9\u5bbd\u5ea6\u81ea\u52a8\u5206\u914d\u7684\u5bfc\u822a\u6548\u679c\u793a\u610f\"><\/p>\n<h3>\u4e09\u3001\u6700\u540e\u603b\u7ed3\u4e00\u4e0b<\/h3>\n<p>\u6700\u540e\u603b\u7ed3\u4e00\u4e0b\uff1a<\/p>\n<ul>\n<li><code>flex:initial<\/code>\u8868\u793a\u9ed8\u8ba4\u7684flex\u72b6\u6001\uff0c\u65e0\u9700\u4e13\u95e8\u8bbe\u7f6e\uff0c\u9002\u5408\u5c0f\u63a7\u4ef6\u5143\u7d20\u7684\u5206\u5e03\u5e03\u5c40\uff0c\u6216\u8005\u67d0\u4e00\u9879\u5185\u5bb9\u52a8\u6001\u53d8\u5316\u7684\u5e03\u5c40\uff1b<\/li>\n<li><code>flex:0<\/code>\u9002\u7528\u573a\u666f\u8f83\u5c11\uff0c\u9002\u5408\u8bbe\u7f6e\u5728\u66ff\u6362\u5143\u7d20\u7684\u7236\u5143\u7d20\u4e0a\uff1b<\/li>\n<li><code>flex:none<\/code>\u9002\u7528\u4e8e\u4e0d\u6362\u884c\u7684\u5185\u5bb9\u56fa\u5b9a\u6216\u8005\u8f83\u5c11\u7684\u5c0f\u63a7\u4ef6\u5143\u7d20\u4e0a\uff0c\u5982\u6309\u94ae\u3002<\/li>\n<li><code>flex:1<\/code>\u9002\u5408\u7b49\u5206\u5e03\u5c40\uff1b<\/li>\n<li><code>flex:auto<\/code>\u9002\u5408\u57fa\u4e8e\u5185\u5bb9\u52a8\u6001\u9002\u914d\u7684\u5e03\u5c40\uff1b<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u5185\u5bb9\uff0c\u5199\u4e8e2020\u5e74\u56fd\u5e86\uff0c\u90e8\u5206\u5185\u5bb9\u8282\u9009\u81ea\u660e\u5e74\u4f1a\u51fa\u7248\u7684\u65b0\u4e66\u300aCSS\u65b0\u4e16\u754c\u300b\u3002<\/p>\n<p>\u611f\u8c22\u60a8\u7684\u9605\u8bfb\uff0c\u5982\u679c\u60a8\u89c9\u5f97\u672c\u6587\u5185\u5bb9\u8fd8\u4e0d\u9519\uff0c\u6b22\u8fce\u5206\u4eab\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f618.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9541\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9541<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/flex-0-1-none-cover.png\" width=\"161\" height=\"101\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>flex:initial\u9002\u5408\u5c0f\u90e8\u4ef6\u5143\u7d20\u7684\u5206\u5e03\u5e03\u5c40\uff0cflex:0\u9002\u5408\u7528\u5230\u66ff\u6362\u5143\u7d20\u7684\u573a\u666f\uff0cflex:none\u9002\u5408\u6309\u94ae\u7b49\u4e0d\u6362\u884c\u7684\u5c0f\u63a7\u4ef6\uff0cflex:1\u9002\u5408\u7b49\u5206\u5e03\u5c40\uff0cflex:auto\u9002\u5408\u57fa\u4e8e\u5185\u5bb9\u52a8\u6001\u9002\u914d\u7684\u5e03\u5c40\uff0c\u5177\u4f53\u7684\u5256\u6790\u53ef\u4ee5\u70b9\u51fb\u94fe\u63a5\u8fdb\u884c\u67e5\u770b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1335,1345,1343,1344,1666,1667,1669,1668,1515,1514],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9541"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=9541"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9541\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=9541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=9541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=9541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}