{"id":5392,"date":"2016-05-20T02:06:37","date_gmt":"2016-05-19T18:06:37","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=5392"},"modified":"2018-10-21T20:32:17","modified_gmt":"2018-10-21T12:32:17","slug":"css3-width-max-contnet-min-content-fit-content","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2016\/05\/css3-width-max-contnet-min-content-fit-content\/","title":{"rendered":"\u7406\u89e3CSS3 max\/min-content\u53cafit-content\u7b49width\u503c"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/\">https:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=5392\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=5392<\/a><\/p>\n<h3>\u4e00\u3001\u4e3a\u4f55\u8981\u8e66\u51fa\u8fd9\u4e9b\u65b0\u73a9\u610f\uff1f<\/h3>\n<p>\u5728CSS3\u7684\u4e16\u754c\u91cc\uff0c<code>width<\/code>\u5c5e\u6027\u53c8\u591a\u4e86\u51e0\u4e2a\u5173\u952e\u5b57\u6210\u5458\uff0c<code>fill-available<\/code>, <code>max-content<\/code>, <code>min-content<\/code>, \u4ee5\u53ca<code>fit-content<\/code>\u3002<\/p>\n<p>\u60f3\u5fc5\u5f88\u591a\u5c0f\u4f19\u4f34\u90fd\u6ca1\u89c1\u8fc7\u3002\u4e0d\u77e5\u5927\u5bb6\u6709\u6ca1\u6709\u8ddf\u6211\u4e00\u6837\u7684\u611f\u89c9\uff0c\u53bb\u5395\u6240\u8e72\u4e86\u4e2a\u5927\u53f7\uff0c\u518d\u56de\u5230\u529e\u516c\u5ba4\u5c31\u4f1a\u9047\u5230\u4e4b\u524d\u6ca1\u89c1\u8fc7\u7684\u524d\u7aef\u65b0\u7279\u6027\u3002<\/p>\n<p>\u50cf\u6211\u8fd9\u79cd\u53ea\u5b66HTML\u548cCSS\u90fd\u6709\u4e9b\u5e94\u63a5\u4e0d\u6687\uff0c\u6211\u60f3\uff0c\u90a3\u4e9bCSS3, HTML5, ES6\/ES7, React, Angular, bootstrap, postcss, node\u90fd\u4f1a\u7684\u5c0f\u4f19\u4f34\uff0c\u5e94\u8be5\u6bcf\u5929\u90fd\u53ea\u77613-4\u4e2a\u5c0f\u65f6\u5427\uff0c\u597d\u5389\u5bb3\uff01<\/p>\n<p>\u51e1\u662f\u5b58\u5728\u5c31\u6709\u5176\u9053\u7406\u3002\u90a3\u4e3a\u4f55\u89c4\u8303\u91cc\u8981\u7ed9\u7a00\u677e\u5e38\u89c1\u7684<code>width<\/code>\u5c5e\u6027\u52a0\u51e0\u4e2a\u5173\u952e\u5b57\u5462\uff1f<\/p>\n<p>\u5927\u5bb6\u8bf4\u6211\u662f\u5148\u8bb2\u5404\u4e2a\u5c5e\u6027\u503c\u8868\u793a\u7684\u542b\u4e49\uff0c\u8fd8\u662f\u5148\u8bb2\u8bb2\u4e3a\u4ec0\u4e48\u8981\u5f04\u8fd9\u4e9b\u65b0\u5c5e\u6027\u503c\u5462\uff1f<\/p>\n<p>\u4e00\u756a\u6df1\u601d\u719f\u8651\uff0c\u6211\u51b3\u5b9a\u2026\u2026\u5148\u8bb2\u8bb2<a href=\"https:\/\/caniuse.com\/intrinsic-width\/embed\" rel=\"noopener\" target=\"_blank\">\u517c\u5bb9\u6027<\/a>\u2026\u2026<img decoding=\"async\" src=\"https:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/13.gif\" align=\"absmiddle\"><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-10_004814.png\" width=\"554\" height=\"261\" alt=\"\u5bbd\u5ea6\u5c3a\u5bf8\u517c\u5bb9\u6027\" class=\"alignnone\" \/><\/p>\n<p>\u57fa\u672c\u4e0a\uff0c\u79fb\u52a8\u7aef\u5df2\u7ecf\u53ef\u4ee5\u6109\u5feb\u5730\u4f7f\u7528\u4e86\u3002<img decoding=\"async\" src=\"https:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/99.gif\" align=\"absmiddle\"><\/p>\n<p>\u636e\u6211\u6d4b\u8bd5\uff0c\u76ee\u524d\u8fd8\u79bb\u4e0d\u5f00\u79c1\u6709\u524d\u7f00\uff0c\u4f8b\u5982\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.min-content {\n    width: -webkit-min-content;\n    width: -moz-min-content;\n    width: min-content;    \n}<\/pre>\n<\/div>\n<p>\u597d\u4e86\uff0c\u8981\u5f00\u59cb\u5f80\u6df1\u7684\u5730\u65b9\u8bb2\u4e86\u3002<\/p>\n<p>\u867d\u7136\uff0c\u4f5c\u4e3a\u540d\u8bcd<code>fill-available<\/code>, <code>max-content<\/code>, <code>min-content<\/code>, \u4ee5\u53ca<code>fit-content<\/code>\u90fd\u662f\u65b0\u9c9c\u9762\u5b54\uff0c\u4f46\u662f\uff0c\u5b9e\u9645\u4e0a\uff0c\u5728CSS2.1\u7684\u65f6\u5019\uff0c\u5c31\u6709\u7c7b\u4f3c\u7684\u5c3a\u5bf8\u6982\u5ff5\u2026\u2026<\/p>\n<h3>\u4e8c\u3001CSS2.1\u7684\u5c3a\u5bf8\u4f53\u7cfb<\/h3>\n<p>\u5728CSS2.1\u7684\u4e16\u754c\u4e2d\uff0c\u5e38\u89c1\u7684\u5c3a\u5bf8\u5206\u4e3a\u8fd9\u51e0\u7c7b\uff1a<br \/>\n<strong>1. \u5145\u5206\u5229\u7528\u53ef\u7528\u7a7a\u95f4<\/strong><br \/>\n\u4f8b\u5982\uff0c\u4e00\u4e9b<code>div<\/code>\u5143\u7d20\u9ed8\u8ba4\u5bbd\u5ea6100%\u7236\u5143\u7d20\uff0c\u8fd9\u79cd\u5145\u5206\u5229\u7528\u53ef\u7528\u7a7a\u95f4\u7684\u884c\u4e3a\u5c31\u79f0\u4e3a\u201c<code>fill-available<\/code>\u201d\u3002<\/p>\n<p><strong>2. \u6536\u7f29\u4e0e\u5305\u88f9<\/strong><br \/>\n\u5178\u578b\u4ee3\u8868\u5c31\u662f\u6d6e\u52a8\uff0c\u7edd\u5bf9\u5b9a\u4f4d\u4ee5\u53ca<code>inline-block<\/code>\uff0c\u82f1\u6587\u79f0\u4e3a\u201cshrink-to-fit\u201d\uff0c\u76f4\u8bd1\u4e3a\u201c\u6536\u7f29\u5230\u5408\u9002\u201d\uff0c\u8fd9\u79cd\u76f4\u8bd1\u5f80\u5f80\u90fd\u662f\u4e0d\u51c6\u786e\u7684\uff0c\u8fd9\u79cd\u884c\u4e3a\u8868\u73b0\u786e\u5b9e\u5f88\u96be\u63cf\u8ff0\uff0c\u6709\u4e9b\u53ea\u53ef\u610f\u4f1a\u4e0d\u80fd\u8a00\u4f20\u7684\u611f\u89c9\uff0c\u800c\u6211\u81ea\u5df1\u4e00\u76f4\u4ee5\u201c\u5305\u88f9\u6027\u201d\u4f5c\u4e3a\u7406\u89e3\u3002\u5728CSS3\u4e2d\u6709\u4e2a\u4e13\u6709\u7684\u5173\u952e\u540d\u79f0\uff0c<code>fit-content<\/code>.<\/p>\n<p><strong>3. \u6536\u7f29\u5230\u6700\u5c0f<\/strong><br \/>\n\u8fd9\u4e2a\u57fa\u672c\u4e0a\u5c31\u51fa\u73b0\u5728<code>table-layout<\/code>\u4e3a<code>auto<\/code>\u7684\u8868\u683c\u4e2d\uff0c\u60f3\u5fc5\u6709\u7ecf\u9a8c\u7684\u5c0f\u4f19\u4f34\u4e00\u5b9a\u89c1\u8fc7\u4e0b\u9762\u8fd9\u6837\u4e00\u67f1\u64ce\u5929\u7684\u76db\u51b5\u7684\u5427\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201605\/2016-05-19_231505.png\" width=\"384\" height=\"226\" alt=\"\u8868\u683c\u4e00\u67f1\u64ce\u5929\u622a\u56fe\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u5927\u5bb6\u7a7a\u95f4\u90fd\u4e0d\u591f\u7684\u65f6\u5019\uff0c\u6587\u5b57\u80fd\u65ad\u7684\u5c31\u65ad\uff0c\u4e2d\u6587\u662f\u968f\u4fbf\u65ad\u7684\uff0c\u82f1\u6587\u5355\u8bcd\u4e0d\u80fd\u65ad\u3002\u4e8e\u662f\u4e4e\uff0c\u7b2c\u4e00\u5217\u88ab\u65e0\u60c5\u5730\u6bcf\u4e2a\u5b57\u90fd\u65ad\u6389\uff0c\u5f62\u6210\u4e00\u67f1\u64ce\u5929\u3002\u8fd9\u79cd\u884c\u4e3a\u79f0\u4e4b\u4e3a\u201cpreferred minimum width\u201d\u6216\u8005\u201cminimum content width\u201d\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u672c\u6587\u7684\u91cd\u70b9\u89d2\u8272\u4e4b\u4e00<code>min-content<\/code>\uff0c\u6362\u4e86\u4e00\u4e2a\u66f4\u52a0\u89c4\u8303\u597d\u542c\u7684\u540d\u5b57\u4e86\u3002\u5b9e\u9645\u4e0a\uff0c\u5927\u5bb6\u4e5f\u770b\u5230\u4e86\uff0c<code>min-content<\/code>\u8fd9\u79cd\u5c3a\u5bf8\u7279\u6027\uff0c<code>display:table-cell<\/code>\u5b9e\u9645\u4e0a\u5c31\u6709\uff0c\u4f46\u662f\uff0c\u7531\u4e8e\u6ca1\u6709\u660e\u786e\u7684\u540d\u8bcd\u6216\u6982\u5ff5\uff0c\u5927\u5bb6\u90fd\u4e0d\u77e5\u9053\uff0c\u90fd\u662f\u7a00\u91cc\u7cca\u6d82\u6709\u6b64\u8868\u73b0\uff0c\u7a76\u5176\u6839\u672c\u5c31\u4e0d\u6e05\u695a\u4e86\u3002<\/p>\n<p><strong>4. \u8d85\u51fa\u5bb9\u5668\u9650\u5236<\/strong><br \/>\n\u4e0a\u97621~3\u60c5\u51b5\uff0c\u9664\u975e\u6709\u660e\u786e\u7684<code>width<\/code>\u76f8\u5173\u8bbe\u7f6e\uff0c\u5426\u5219\u5c3a\u5bf8\u90fd\u4e0d\u4f1a\u4e3b\u52a8\u8d85\u8fc7\u5bb9\u5668\u5bbd\u5ea6\u7684\uff0c\u4f46\u662f\uff0c\u5b58\u5728\u4e00\u4e9b\u7279\u6b8a\u60c5\u51b5\uff0c\u4f8b\u5982\uff0c\u8fde\u7eed\u7684\u82f1\u6587\u6570\u5b57\uff0c\u597d\u957f\u597d\u957f\uff1b\u6216\u8005\u5185\u8054\u5143\u7d20\u88ab\u8bbe\u7f6e\u4e86<code>white-space:nowrap<\/code>\uff0c\u5219\u8868\u73b0\u4e3a\u4e00\u6c5f\u6625\u6c34\u5411\u4e1c\u6d41\u3002<\/p>\n<p>\u4f8b\u5982\u4e0b\u9762\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.box {\n    display: inline-block;\n    width: 100px; height: 20px; \n    padding: 10px;\n    background-color: #f0f3f9;\n    white-space: nowrap;\n}<\/pre>\n<\/div>\n<p><em style=\"display: inline-block;width: 100px; height: 20px; padding: 10px;background-color: #f0f3f9; white-space: nowrap;\">\u5c3a\u5bf8\u4e3b\u52a8\u8d85\u8fc7\u5bb9\u5668\u5bbd\u5ea6\uff0c\u6070\u5982\u4e00\u6c5f\u6625\u6c34\u5411\u4e1c\u6d41\u3002<\/em><\/p>\n<p><code>max-content<\/code>\u7684\u8868\u73b0\u4e0e\u4e4b\u6709\u4e9b\u7c7b\u4f3c\uff0c\u5177\u6709\u6536\u7f29\u7279\u6027\uff0c\u540c\u65f6\u6700\u5927\u5185\u5bb9\u5bbd\u5ea6\u3002<\/p>\n<p><span class=\"s\">\/\/ &#8212;&#8212;&#8212; \u6709\u5fc5\u8981\u6765\u6839\u4f4e\u8c03\u7684\u5206\u9694\u7ebf &#8212;&#8212;&#8212;-<\/span><\/p>\n<p>\u597d\u4e86\uff0c\u81f3\u6b64\uff0c\u5927\u5bb6\u4f1a\u53d1\u73b0\uff0c<code>fill-available<\/code>, <code>max-content<\/code>, <code>min-content<\/code>, \u4ee5\u53ca<code>fit-content<\/code>\u786e\u5b9e\u5728CSS2.1\u7684\u65f6\u5019\uff0c\u5c31\u6709\u7c7b\u4f3c\u6982\u5ff5\u3002<\/p>\n<p>\u4e0b\u9762\u95ee\u9898\u6765\u4e86\uff0c\u65e2\u7136CSS2.1\u8fd9\u4e9b\u7279\u6027\u90fd\u6709\u4e86\uff0c\u90a3\u8fd8\u8981\u989d\u5916\u5f04\u4e00\u4e9b\u65b0\u503c\u8fc7\u6765\u5e72\u561b\u5462\uff1f\u5c82\u4e0d\u662f\u767d\u767d\u589e\u52a0\u5b66\u4e60\u6210\u672c\u554a\uff1f<\/p>\n<p>\u6211\u8ba4\u4e3a\u67093\u4e2a\u597d\u5904\uff1a<\/p>\n<ol>\n<li>\u65b9\u4fbf\u67d0\u4e9b\u5e03\u5c40\u7684\u5b9e\u73b0\uff1b<\/li>\n<li><strong>\u6700\u91cd\u8981\u7684\u4f5c\u7528\uff1a<\/strong> \u5728\u539f\u6709\u7684display\u6c34\u5e73\u4e0d\u53d8\u7684\u60c5\u51b5\u4e0b\u62e5\u6709\u5143\u7d20\u5176\u4ed6display\u503c\u624d\u6709\u7684\u7279\u6027\uff01<\/li>\n<li>\u8ba9\u6574\u4e2aCSS\u4e16\u754c\u7684size\u4f53\u7cfb\u66f4\u52a0\u76f4\u89c2\u548c\u5b8c\u5584\uff1b<\/li>\n<\/ol>\n<p>\u6211\u4eec\u4e0b\u9762\u4e0d\u59a8\u4e00\u8fb9\u4e86\u89e3\u4e0b\u5404\u4e2a<code>width<\/code>\u503c\u7684\u4f5c\u7528\u548c\u8868\u73b0\uff0c\u4e00\u8fb9\u9a8c\u8bc1\u6211\u4e0a\u9762\u6240\u8bf4\u7684\u597d\u5904\uff01<\/p>\n<h3>\u4e09\u3001\u7406\u89e3width:fill-available<\/h3>\n<p><code>width:fill-available<\/code>\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u6bd4\u65b9\u8bf4\uff0c\u6211\u4eec\u5728\u9875\u9762\u4e2d\u6254\u4e00\u4e2a\u6ca1\u6709\u5176\u4ed6\u6837\u5f0f\u7684<code>&lt;div&gt;<\/code>\u5143\u7d20\uff0c\u5219\uff0c\u6b64\u65f6\uff0c\u8be5<code>&lt;div&gt;<\/code>\u5143\u7d20\u7684<code>width<\/code>\u8868\u73b0\u5c31\u662f<code>fill-available<\/code>\u81ea\u52a8\u586b\u6ee1\u5269\u4f59\u7684\u7a7a\u95f4\u3002\u4e5f\u5c31\u662f\u6211\u4eec\u5e73\u5e38\u6240\u8bf4\u7684\u76d2\u6a21\u578b\u7684<code>margin<\/code>,<code>border<\/code>,<code>padding<\/code>\u7684\u5c3a\u5bf8\u586b\u5145\u3002<\/p>\n<p>\u51fa\u73b0<code>fill-available<\/code>\u5173\u952e\u5b57\u503c\u7684\u4ef7\u503c\u5728\u4e8e\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba9\u5143\u7d20\u7684100%\u81ea\u52a8\u586b\u5145\u7279\u6027\u4e0d\u4ec5\u4ec5\u5728<code>block<\/code>\u6c34\u5e73\u5143\u7d20\u4e0a\uff0c\u5176\u4ed6\u5143\u7d20\uff0c\u4f8b\u5982\uff0c\u6211\u4eec\u4e00\u76f4\u8ba4\u4e3a\u7684\u5305\u88f9\u6536\u7f29\u7684<code>inline-block<\/code>\u5143\u7d20\u4e0a\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>div { display:inline-block; width:fill-available; }<\/pre>\n<\/div>\n<p>\u6b64\u65f6\uff0c\u5143\u7d20\u517c\u5177\u4e86\u5757\u72b6\u5143\u7d20\u7684\u81ea\u52a8\u586b\u5145\u7279\u6027\u4ee5\u53ca\u5185\u8054\u5143\u7d20\u7684\u5b9a\u4f4d\u5bf9\u9f50\u7b49\u7279\u6027\u3002\u4e8e\u662f\uff0c\uff08\u4f8b\u5982\uff09\u6211\u4eec\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>line-height<\/code>\u8ba9\u4e00\u4e2a\u5757\u72b6\u8868\u73b0\u7684\u5143\u7d20\u5782\u76f4\u5c45\u4e2d\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201605\/width-fill-available.html\" target=\"_blank\">CSS3 width:fill-available\u4e0b\u7684\u5782\u76f4\u5c45\u4e2ddemo<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201605\/2016-05-20_004332.png\" width=\"782\" height=\"311\" alt=\"\u5757\u72b6\u5143\u7d20\u5c3a\u5bf8\u8868\u73b0\u5185\u8054\u5143\u7d20\u5782\u76f4\u5c45\u4e2d\u884c\u4e3a\" class=\"alignnone\" \/><\/p>\n<p>\u5b8c\u6574\u5173\u952eCSS\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>\n.box {\n    height: 200px; \n    <span style=\"color:green;\">\/* \u884c\u9ad8\u63a7\u5236\u5782\u76f4\u5c45\u4e2d *\/<\/span>\n    line-height: 200px;\n}\n.fill-available {\n    <span style=\"color:green;\">\/* \u5143\u7d20\u5185\u8054\uff0c\u54cd\u5e94\u884c\u9ad8\u548cvertical-align\u63a7\u5236 *\/<\/span>\n    display: inline-block;\n    vertical-align: middle;\n    \n    <span style=\"color:green;\">\/* \u5bbd\u5ea6\u5982\u5757\u72b6\u5143\u7d20\u822c\u8868\u73b0 *\/<\/span>\n    width: -webkit-fill-available;\n    width: -moz-fill-available;\n    width: -moz-available;    <span style=\"color:green;\">\/* FireFox\u76ee\u524d\u8fd9\u4e2a\u751f\u6548 *\/<\/span>\n    width: fill-available;\n}<\/pre>\n<\/div>\n<p>\u6b63\u5982\u4e0a\u9762\u6ce8\u91ca\u6240\u63d0\u5230\u7684\uff0cFireFox\u6d4f\u89c8\u5668\u4e0b\uff0c\u76ee\u524d(2016-05-20)\u4e0d\u662f\u6807\u51c6\u7684<code>-moz-fill-available<\/code>\uff0c\u800c\u662f<code>-moz-available<\/code>\uff0c\u4f30\u8ba1\u8fc7\u4e2a\u51e0\u4e2a\u7248\u672c\u53ef\u80fd\u4f1a\u8c03\u6574\u8fc7\u6765\u3002<\/p>\n<h3>\u56db\u3001\u7406\u89e3width:max-content<\/h3>\n<p><code>max-content<\/code>\u7684\u884c\u4e3a\u8868\u73b0\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff0c\u5047\u8bbe\u6211\u4eec\u7684\u5bb9\u5668\u6709\u8db3\u591f\u7684\u5bbd\u5ea6\uff0c\u8db3\u591f\u7684\u7a7a\u95f4\uff0c\u6b64\u65f6\uff0c\u6240\u5360\u636e\u7684\u5bbd\u5ea6\u662f\u5c31\u662f<code>max-content<\/code>\u6240\u8868\u793a\u7684\u5c3a\u5bf8\u3002<\/p>\n<p>\u4e0d\u61c2\u6ca1\u5173\u7cfb\uff0c\u6211\u4eec\u770b\u4e00\u4e2a\u5bf9\u6bd4\u793a\u4f8b\uff0c\u4fdd\u8bc1\u7acb\u9a6c\u5c31\u77e5\u9053\uff01<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201605\/width-max-content.html\" target=\"_blank\">CSS3 width:max-content\u5bf9\u6bd4\u6d4b\u8bd5demo<\/a><\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a<code>display:inline-block<\/code>\u548c<code>width:max-content<\/code>\u7684\u5bf9\u6bd4demo\uff0c\u5982\u679c\u59b9\u5b50\u4e0b\u9762\u7684\u6587\u5b57\u63cf\u8ff0\u77ed\uff0c\u5927\u5bb6\u662f\u770b\u4e0d\u51fa\u533a\u522b\u7684\u3002\u4f46\u662f\uff0c\u5982\u679c\u6587\u5b57\u5185\u5bb9\u50cfdemo\u6240\u5c55\u793a\u7684\u8fd9\u4e48\u957f\uff0c\u563b\u563b\u563b\u563b~~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201605\/xixi.jpg\" width=\"150\" height=\"113\" alt=\"\u5468\u661f\u9a70 \u7b11\" class=\"alignnone\" \/><\/p>\n<p>\u4f1a\u53d1\u73b0\uff0c<code>width:max-content<\/code>\u8868\u73b0\u5f97\u597d\u50cf\u8bbe\u7f6e\u4e86white-space:nowrap\u4e00\u6837\uff0c\u6587\u5b57\u4e00\u9a6c\u5e73\u5ddd\u4e0b\u53bb\uff0c\u5143\u7d20\u7684\u5bbd\u5ea6\u4e5f\u53d8\u6210\u4e86\u8fd9\u4e9b\u6587\u5b57\u4e00\u884c\u663e\u793a\u7684\u5bbd\u5ea6\uff01\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u4e48\u8868\u73b0\u5462\uff1f\u5b9a\u4e49\u5c31\u662f\u8fd9\u6837\u7684\uff0c\u5bf9\u5427\uff0c\u6211\u4eec\u5bf9\u7167\u4e0b\uff0c\u9996\u5148\uff0c\u5047\u8bbe\u6211\u4eec\u7684\u5bb9\u5668\u6709\u8db3\u591f\u7684\u7a7a\u95f4\uff0c\u4f60\u60f3\u5440\uff0c\u5bb9\u5668\u8db3\u591f\u7a7a\u95f4\uff0c\u90a3\u4e0b\u9762\u7684\u63cf\u8ff0\u6587\u5b57\u80af\u5b9a\u4e00\u884c\u663e\u793a\u4e86\uff0c\u6b64\u65f6\uff0c\u4e0a\u9762\u7684\u56fe\u7247\u548c\u4e0b\u9762\u7684\u6587\u5b57\u90a3\u4e2a\u5185\u5bb9\u5bbd\u5ea6\u5927\uff0c\u81ea\u7136\u662f\u6587\u5b57\u5566\uff0c\u6240\u8c13<code>max-content<\/code>\u5c31\u662f\u503c\u91c7\u7528\u5bbd\u5ea6\u5927\u7684\u90a3\u4e2a\u5185\u5bb9\u7684\u5bbd\u5ea6\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-10_005106.png\" width=\"502\" height=\"361\" alt=\"max-content\u7684\u8868\u73b0\u5bf9\u6bd4\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<h3>\u4e94\u3001\u7406\u89e3width:min-content<\/h3>\n<p><code>min-content<\/code>\u5bbd\u5ea6\u8868\u793a\u7684\u5e76\u4e0d\u662f\u5185\u90e8\u90a3\u4e2a\u5bbd\u5ea6\u5c0f\u5c31\u662f\u90a3\u4e2a\u5bbd\u5ea6\uff0c\u800c\u662f\uff0c\u91c7\u7528\u5185\u90e8\u5143\u7d20\u6700\u5c0f\u5bbd\u5ea6\u503c\u6700\u5927\u7684\u90a3\u4e2a\u5143\u7d20\u7684\u5bbd\u5ea6\u4f5c\u4e3a\u6700\u7ec8\u5bb9\u5668\u7684\u5bbd\u5ea6\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u660e\u767d\u8fd9\u91cc\u7684\u201c\u6700\u5c0f\u5bbd\u5ea6\u503c\u201d\u662f\u4ec0\u4e48\u610f\u601d\u3002\u66ff\u6362\u5143\u7d20\uff0c\u4f8b\u5982\u56fe\u7247\u7684\u6700\u5c0f\u5bbd\u5ea6\u503c\u5c31\u662f\u56fe\u7247\u5448\u73b0\u7684\u5bbd\u5ea6\uff0c\u5bf9\u4e8e\u6587\u672c\u5143\u7d20\uff0c\u5982\u679c\u5168\u90e8\u662f\u4e2d\u6587\uff0c\u5219\u6700\u5c0f\u5bbd\u5ea6\u503c\u5c31\u662f\u4e00\u4e2a\u4e2d\u6587\u7684\u5bbd\u5ea6\u503c\uff1b\u5982\u679c\u5305\u542b\u82f1\u6587\uff0c\u56e0\u4e3a\u9ed8\u8ba4\u82f1\u6587\u5355\u8bcd\u4e0d\u6362\u884c\uff0c\u6240\u4ee5\uff0c\u6700\u5c0f\u5bbd\u5ea6\u53ef\u80fd\u5c31\u662f\u91cc\u9762\u6700\u957f\u7684\u82f1\u6587\u5355\u8bcd\u7684\u5bbd\u5ea6\u3002So\uff0c\u5927\u5bb6\u660e\u767d\u7684\u8bf4\u3002<\/p>\n<p>\u8fd8\u6ca1\u5b8c\u5168\u5f04\u61c2\u6ca1\u5173\u7cfb\uff0c\u6211\u4eec\u770b\u4e00\u4e2a\u5bf9\u6bd4\u4f8b\u5b50\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201605\/width-min-content.html\" target=\"_blank\">CSS3 width:min-content\u5bf9\u6bd4demo<\/a><\/p>\n<p>\u540c\u6837\u7684\u662f\u548c<code>display:inline-block<\/code>\u505a\u6bd4\u8f83\uff0c<code>display:inline-block<\/code>\u867d\u7136\u4e5f\u5177\u6709\u6536\u7f29\u7279\u6027\uff0c\u4f46\u5bbd\u5ea6\u968f\u6700\u5927\u957f\u5ea6\u957f\u7684\u90a3\u4e00\u4e2a\uff08\u540c\u65f6\u4e0d\u8d85\u8fc7\u53ef\u7528\u5bbd\u5ea6\uff09\u3002\u800c<code>width:min-content<\/code>\u7684\u6700\u7ec8\u5bbd\u5ea6\u662f\u56fe\u7247\u548c\u6587\u5b57\u6700\u5c0f\u5bbd\u5ea6\u503c\u91cc\u9762\u5927\u7684\u90a3\u4e00\u4e2a\u3002<\/p>\n<p>\u5728\u672c\u4f8b\u5b50\u4e2d\uff0c\u56fe\u7247\u7684\u5bbd\u5ea6\u6700\u5c0f\u503c\u662f256\u50cf\u7d20\uff0c\u4e0d\u80fd\u518d\u7f29\u4e86\uff1b\u800c\u6587\u5b57\u7684\u6700\u5c0f\u5bbd\u5ea6\u503c\u662f\u5b57\u7b26<code>display:inline-<\/code>\u6240\u5360\u636e\u7684\u5bbd\u5ea6\uff0c\u56e0\u4e3a<code>inline-block<\/code>\u540e\u9762\u7684<code>block<\/code>\u53ef\u4ee5\u6362\u884c\uff0c\u4e2d\u6587\u4e0d\u7528\u8c08\uff0c\u5929\u751f\u88ab\u6362\u884c\u7684\u547d\uff0c\u663e\u7136<code>display:inline-<\/code>\u6240\u5360\u636e\u7684\u5bbd\u5ea6\u8981\u8fdc\u8fdc\u5c0f\u4e8e256\u50cf\u7d20\uff0c\u56e0\u6b64\uff0c\u6700\u7ec8\u6211\u4eec\u5143\u7d20\u7684\u5bbd\u5ea6\u5c31\u662f256\u50cf\u7d20\uff0c\u8089\u773c\u770b\u5230\u7684\u5c31\u662f\u81ea\u9002\u5e94\u56fe\u7247\u5bbd\u5ea6\u7684\u4e00\u4e2a\u6548\u679c\u3002\u5728CSS2.1\u7684\u4e16\u754c\u91cc\uff0c\u8fd9\u79cd\u6548\u679c\u5b9e\u9645\u4e0a\u662f\u4e0d\u597d\u5b9e\u73b0\u7684\uff0c\u8981\u501f\u52a9\u5355\u5143\u683c\u7279\u6027\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201605\/2016-05-20_014028.png\" width=\"259\" height=\"265\" alt=\"\u6ca1\u6709\u56fe\u7247\u6587\u5b57\u7684\u6700\u5c0f\u5bbd\u5ea6\u503c\" class=\"alignnone\" \/><\/p>\n<p>\u4e0b\u56fe\u4e3a\u5bf9\u6bd4\u6548\u679c\u622a\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-10_005340.png\" width=\"415\" height=\"407\" alt=\"min-content\u4e0b\u7684\u5bf9\u6bd4\u6548\u679c\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<h3>\u516d\u3001\u7406\u89e3width:fit-content<\/h3>\n<p><code>width:fit-content<\/code>\u4e5f\u662f\u5e94\u8be5\u6bd4\u8f83\u597d\u7406\u89e3\u7684\uff0c\u201cshrink-to-fit\u201d\u8868\u73b0\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u548cCSS2.1\u4e2d\u7684<code>float<\/code>, <code>absolute<\/code>, <code>inline-block<\/code>\u7684\u5c3a\u5bf8\u6536\u7f29\u8868\u73b0\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>OK\uff0c\u7136\u540e\uff0c\u6709\u5c0f\u4f19\u4f34\u4f1a\u7591\u95ee\uff0c\u65e2\u7136\u8ddf\u5f88\u591aCSS\u58f0\u660e\u6709\u4e00\u6837\u7684\u8868\u73b0\uff0c\u90a3\u4e3a\u4ec0\u4e48\u8fd8\u8981\u518d\u5f04\u4e2a\u65b0\u4e1c\u897f\u5462\uff1f<\/p>\n<p>\u5c31\u62ff\u6c34\u5e73\u5c45\u4e2d\u6548\u679c\u4e3e\u4f8b\uff0c\u9996\u5148\u6d6e\u52a8\u80af\u5b9a\u4e0d\u884c\uff0c\u56e0\u4e3a\u53ea\u6709\u5de6\u6d6e\u52a8\u548c\u53f3\u6d6e\u52a8\uff1b\u7edd\u5bf9\u5b9a\u4f4d\u538b\u6839\u4e0d\u5360\u636e\u7a7a\u95f4\uff0c\u666e\u901a\u6d41\u4e2d\u6839\u672c\u65e0\u6cd5\u5e94\u7528\uff0c\u800c<code>inline-block<\/code>\u9700\u8981\u7236\u7ea7\u4f7f\u7528<code>text-align:center<\/code>\uff0c\u800c\u672c\u8eab\u53ef\u80fd\u8fd8\u9700\u8981<code>text-align:left<\/code>\u7565\u70e6\u3002<\/p>\n<p>\u800c<code>width:fit-content<\/code>\u53ef\u4ee5\u6ca1\u6709\u8fd9\u4e9b\u70e6\u607c\uff0c\u56e0\u4e3a\uff0c<code>width:fit-content<\/code>\u53ef\u4ee5\u5b9e\u73b0\u5143\u7d20\u6536\u7f29\u6548\u679c\u7684\u540c\u65f6\uff0c\u4fdd\u6301\u539f\u672c\u7684block\u6c34\u5e73\u72b6\u6001\uff0c\u4e8e\u662f\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>margin:auto<\/code>\u5b9e\u73b0\u5143\u7d20\u5411\u5185\u81ea\u9002\u5e94\u540c\u65f6\u7684\u5c45\u4e2d\u6548\u679c\u4e86\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201605\/width-fit-content.html\" target=\"_blank\">CSS3 width:fit-content\u4f7f\u7528\u4e0emargin auto\u4e0b\u6c34\u5e73\u5c45\u4e2ddemo<\/a><\/p>\n<p>\u7ed3\u679c\uff0c\u7b80\u7b80\u5355\u5355\u5c31\u5c45\u4e2d\u4e86\uff0c\u4e5f\u4e0d\u8981\u62c5\u5fc3\u5176\u4ed6\u5143\u7d20\u4f1a\u8ddf\u5728\u540e\u9762\u4e00\u884c\u663e\u793a\u4e86\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-10_005451.png\" width=\"418\" height=\"223\" alt=\"\u6536\u7f29\u8868\u73b0\u4e0bmargin:auto\u5c45\u4e2d\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<h3>\u4e03\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>CSS\u4e2d\u7684\u5143\u7d20\u5c3a\u5bf8\u5206\u4e3a\u4e24\u7c7b\uff0c\u4e00\u7c7b\u53eb\u505a\u201c\u5185\u90e8\u5c3a\u5bf8\u201d\uff0c\u82f1\u6587\u5199\u4f5c&#8221;Intrinsic Sizing&#8221;\uff0c\u5c3a\u5bf8\u7531\u5185\u90e8\u5143\u7d20\u51b3\u5b9a\uff1b\u8fd8\u6709\u4e00\u7c7b\u53eb\u505a\u201c\u5916\u90e8\u5c3a\u5bf8\u201d\uff0c\u82f1\u6587\u5199\u4f5c&#8221;Extrinsic Sizing&#8221;\uff0c\u5bbd\u5ea6\u7531\u5916\u90e8\u5143\u7d20\u51b3\u5b9a\u3002<\/p>\n<p>\u8003\u8003\u5927\u5bb6\uff1a<br \/>\n<code>fill-available<\/code>, <code>max-content<\/code>, <code>min-content<\/code>, <code>fit-content<\/code>\u8fd94\u4e2a\u5173\u952e\u5b57\uff0c\u54ea\u4e2a\u662f\u201c\u5185\u90e8\u5c3a\u5bf8\u201d\uff0c\u54ea\u4e2a\u662f\u201c\u5916\u90e8\u5c3a\u5bf8\u201d\u5462\uff1f<\/p>\n<p>\u770b\u672c\u6587\u4e4b\u524d\u96be\u5ea690\uff0c\u770b\u5b8c\u672c\u6587\u4e4b\u540e\uff0c\u96be\u5ea610. \u5982\u679c\u4f60\u89c9\u5f97\u8fd8\u662f\u5f88\u96be\uff0c\u5efa\u8bae\u518d\u770b\u4e00\u904d\uff0c\u7136\u540e\u4e0d\u65ad\u9012\u5f52\u3002 <img decoding=\"async\" src=\"\/\/mat1.gtimg.com\/www\/mb\/images\/face\/13.gif\" align=\"absmiddle\"><\/p>\n<p>\u597d\u4e86\uff0c\u5176\u4ed6\u5e9f\u8bdd\u5c31\u4e0d\u591a\u8bf4\u4e86\uff0c\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u4ea4\u6d41\uff01<\/p>\n<p> <img decoding=\"async\" src=\"\/\/mat1.gtimg.com\/www\/mb\/images\/face\/14.gif\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=5392\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=5392<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728CSS3\u7684\u4e16\u754c\u91cc\uff0cwidth\u5c5e\u6027\u53c8\u591a\u4e86\u51e0\u4e2a\u5173\u952e\u5b57\u6210\u5458\uff0cfill-available, max-content, min-content, \u4ee5\u53cafit-content\u3002<\/p>\n<p>\u672c\u6587\u5c31\u5c06\u5206\u6790\u4e0e\u4ecb\u7ecd\u8fd9\u51e0\u4e2a\u5173\u952e\u5b57\uff0c\u987a\u4fbf\u5e2e\u5fd9\u7406\u4e00\u4e0bCSS\u4e16\u754c\u4e2d\u7684\u5c3a\u5bf8\u6982\u5ff5\uff0c\u76f8\u4fe1\u672c\u6587\u7684\u5185\u5bb9\u4e0d\u4ec5\u5bf9\u4e8eCSS3\u7684\u5b66\u4e60\uff0c\u5305\u62ec\u5bf9CSS2.1\u6574\u4e2a\u5c3a\u5bf8\u7684\u8ba4\u77e5\u90fd\u4f1a\u6709\u4e00\u5b9a\u7684\u5e2e\u52a9\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":[177,1056,1059,45,1057,1058,519,574],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/5392"}],"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=5392"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/5392\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}