{"id":79,"date":"2024-12-01T09:41:54","date_gmt":"2024-12-01T01:41:54","guid":{"rendered":"https:\/\/note.yuncrown.com\/?p=79"},"modified":"2024-12-01T10:01:14","modified_gmt":"2024-12-01T02:01:14","slug":"css%e4%bc%b8%e7%bc%a9%e7%9b%92%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/note.yuncrown.com\/index.php\/2024\/12\/01\/css%e4%bc%b8%e7%bc%a9%e7%9b%92%e6%a8%a1%e5%9e%8b\/","title":{"rendered":"CSS\u4f38\u7f29\u76d2\u6a21\u578b"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u5143\u7d20\u8bbe\u7f6e\u4e3a\u4f38\u7f29\u5bb9\u5668\uff08\u5f00\u542fflex\u5e03\u5c40\uff09\uff08\u7236\u5bb9\u5668\u5199\u6837\u5f0f\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* \u7236\u5bb9\u5668\u5f00\u542fflex\u5e03\u5c40\uff0c\u53ea\u6709\u76f4\u63a5\u5b50\u5143\u7d20\u662f\u4f38\u7f29\u9879\u76ee\uff08\u5e94\u8be5\u662f\u53d7\u5f71\u54cd\u7684\u610f\u601d\uff09 *\/\n\/* \u5b50\u5143\u7d20\u6210\u4e3a\u4f38\u7f29\u9879\u76ee\u4f1a\u53d8\u6210\u5757\u5143\u7d20\uff08\u4e0d\u7ba1\u4ee5\u524d\u662f\u5757\uff0c\u884c\u5185\u5757\uff0c\u884c\u5185\uff09 *\/\ndiv {\n\t\/* \u5c06\u8be5\u5143\u7d20\u53d8\u6210\u4f38\u7f29\u5bb9\u5668\uff08\u5f00\u542fflex\u5e03\u5c40\uff09 *\/\n\tdisplay: flex;\n\tdisplay: inline-flex;\/* \u4e0d\u5e38\u7528\uff0c\u4e0d\u7528\u8bb0 *\/\n\n\t\/* \u8c03\u6574\u4e3b\u8f74\u65b9\u5411\uff0c\u6c34\u5e73\u4ece\u5de6\u5230\u53f3\uff0c\u9ed8\u8ba4 *\/\n\tflex-direction: row;\n\t\/* \u8c03\u6574\u4e3b\u8f74\u65b9\u5411\uff0c\u6c34\u5e73\u4ece\u53f3\u5230\u5de6 *\/\n\tflex-direction: row-reverse;\n\t\/* \u8c03\u6574\u4e3b\u8f74\u65b9\u5411\uff0c\u6c34\u5e73\u4ece\u4e0a\u5230\u4e0b *\/\n\tflex-direction: column;\n\t\/* \u8c03\u6574\u4e3b\u8f74\u65b9\u5411\uff0c\u6c34\u5e73\u4ece\u4e0b\u5230\u4e0a *\/\n\tflex-direction: column-reverse;\n\t\/* \u4e0d\u6362\u884c\uff08\u9ed8\u8ba4\uff09 *\/\n\tflex-wrap: nowrap;\n\t\/* \u6362\u884c\uff08\u6362\u884c\u540e\u5982\u679c\u4e0a\u4e0b\u6709\u7a7a\u4f59\u7a7a\u95f4\uff0c\u5143\u7d20\u4e0a\u4e0b\u4f1a\u6709\u95f4\u8ddd\uff09 *\/\n\tflex-wrap: wrap;\n\t\/* \u53cd\u5411\u6362\u884c\uff08\u6309\u7167\u4fa7\u8f74\u53cd\u8f6c\u6362\u884c\uff09 *\/\n\tflex-wrap: wrap-reverse;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>**\u6539\u53d8\u4e86\u4e3b\u8f74\u65b9\u5411\uff0c\u4fa7\u8f74\u4e5f\u968f\u4e4b\u6539\u53d8**<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e3b\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff08\u7236\u5bb9\u5668\u5199\u6837\u5f0f\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n\t\/* \u4e3b\u8f74\u5f00\u59cb\u7684\u4f4d\u7f6e\uff08\u9ed8\u8ba4\u4ece\u5de6\u5230\u53f3\uff0c\u8fd9\u91cc\u662f\u9760\u5de6\uff09 *\/\n\tjustify-content: start;\n\t\/* \u4e3b\u8f74\u7ed3\u675f\u7684\u4f4d\u7f6e\uff08\u9ed8\u8ba4\u4ece\u5de6\u5230\u53f3\uff0c\u8fd9\u91cc\u662f\u9760\u53f3\uff09 *\/\n\tjustify-content: flex-end;\n\t\/* \u4e3b\u8f74\u4e2d\u95f4\u7684\u4f4d\u7f6e\uff08\u9ed8\u8ba4\u4ece\u5de6\u5230\u53f3\uff0c\u8fd9\u91cc\u662f\u4e2d\u95f4\uff09 *\/\n\tjustify-content: center;\n\t\/* \u9879\u76ee\u5747\u5300\u5206\u5e03\u5728\u4e00\u884c\u4e2d\uff0c\u9879\u76ee\u4e4b\u95f4\u8ddd\u79bb\u662f\u9879\u76ee\u4e0e\u8fb9\u7f18\u76842\u500d *\/\n\tjustify-content: first space-around;\n\t\/* \u9879\u76ee\u5747\u5300\u5206\u5e03\u5728\u4e00\u884c\u4e2d\uff0c\u9879\u76ee\u4e4b\u95f4\u8ddd\u79bb\u76f8\u7b49\uff0c\u9879\u76ee\u4e0e\u8fb9\u7f18\u6ca1\u6709\u8ddd\u79bb *\/\n\tjustify-content: space-between;\n\t\/* \u9879\u76ee\u5747\u5300\u5206\u5e03\u5728\u4e00\u884c\u4e2d\uff0c\u9879\u76ee\u4e4b\u95f4\u8ddd\u79bb\u548c\u9879\u76ee\u4e0e\u8fb9\u7f18\u8ddd\u79bb\u76f8\u7b49 *\/\n\tjustify-content: space-evenly;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff08\u53ea\u6709\u4e00\u884c\u60c5\u51b5\uff09\uff08\u7236\u5bb9\u5668\u5199\u6837\u5f0f\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u4fa7\u8f74\u7684\u8d77\u59cb\u4f4d\u7f6e *\/\n\talign-items: flex-start;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u4fa7\u8f74\u7684\u7ed3\u675f\u4f4d\u7f6e *\/\n\talign-items: flex-end;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u4fa7\u8f74\u7684\u4e2d\u95f4\u4f4d\u7f6e *\/\n\talign-items: center;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u6839\u636e\u6587\u5b57\u57fa\u7ebf\u5bf9\u9f50\uff08\u6587\u5b57\u4e0b\u8fb9\u7f18\u5728\u4e00\u6761\u6c34\u5e73\u7ebf\u4e0a\uff09 *\/\n\talign-items: baseline;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u5143\u7d20\u6ca1\u6709\u9ad8\u5ea6\u65f6\u5145\u6ee1\u6574\u4e2a\u7236\u5bb9\u5668\uff0c\u6709\u9ad8\u5ea6\u65f6\u4e0d\u751f\u6548\uff08\u9ed8\u8ba4\uff09 *\/\n\talign-items: stretch;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff08\u591a\u884c\u60c5\u51b5\uff09\uff08\u7236\u5bb9\u5668\u5199\u6837\u5f0f\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u4fa7\u8f74\u8d77\u59cb\u4f4d\u7f6e *\/\n\talign-content: flex-start;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u4fa7\u8f74\u7ed3\u675f\u4f4d\u7f6e *\/\n\talign-content: flex-end;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u4fa7\u8f74\u4e2d\u95f4\u4f4d\u7f6e *\/\n\talign-content: center;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u9879\u76ee\u4e4b\u95f4\u8ddd\u79bb\u662f\u9879\u76ee\u4e0e\u8fb9\u7f18\u76842\u500d *\/\n\talign-content: space-around;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u9879\u76ee\u4e4b\u95f4\u8ddd\u79bb\u76f8\u7b49\uff0c\u9879\u76ee\u4e0e\u8fb9\u7f18\u6ca1\u6709\u8ddd\u79bb *\/\n\talign-content: space-between;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u9879\u76ee\u4e4b\u95f4\u8ddd\u79bb\u76f8\u7b49 *\/\n\talign-content: space-evenly;\n\t\/* \u4fa7\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff0c\u5143\u7d20\u6ca1\u6709\u9ad8\u5ea6\u65f6\u5145\u6ee1\u6574\u4e2a\u7236\u5bb9\u5668\uff08\u9ed8\u8ba4\uff09 *\/\n\talign-content: stretch;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5143\u7d20\u6c34\u5e73\u5782\u76f4\u5c45\u4e2d\uff08.father\uff1a\u7236\u5bb9\u5668\uff0c.child\uff1a\u5b50\u5bb9\u5668\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.father {\n\tdisplay: flex;\n\t\/* \u65b9\u6848\u4e00 *\/\n\tjustify-content: center;\n\talign-items: center;\n}\n.child {\n\t\/* \u65b9\u6848\u4e8c *\/\n\tmargin: auto;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9879\u76ee\u5728\u4e3b\u8f74\u7684\u57fa\u51c6\u957f\u5ea6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n\twidth: 200px;\n\theight: 200px;\n\t\/* \u8bbe\u7f6e\u4f38\u7f29\u9879\u76ee\u5728\u4e3b\u8f74\u4e0a\u7684\u57fa\u51c6\u957f\u5ea6 *\/\n\t\/* \u5982\u679c\u4e3b\u8f74\u662f\u6a2a\u5411\u7684\uff0c\u539f\u6765\u7684\u5bbd\u5931\u6548 *\/\n\t\/* \u5982\u679c\u4e3b\u8f74\u662f\u7eb5\u5411\u7684\uff0c\u539f\u6765\u7684\u9ad8\u5931\u6548 *\/\n\t\/* \u9ed8\u8ba4auto\uff0c\u5c31\u662f\u539f\u6765\u7684\u6570\u503c *\/\n\tflex-basis: 300px;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e3b\u8f74\u62c9\u4f38<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.child {\n\t\/* \u9ed8\u8ba4\u662f0\uff0c\u5c31\u7b97\u4e3b\u8f74\u6709\u5269\u4f59\u7a7a\u95f4\u4e5f\u4e0d\u62c9\u4f38 *\/\n    \/* \u5982\u679c\u6240\u4ee5\u4f38\u7f29\u9879\u76ee\u503c\u90fd\u662f1\uff0c\u7b49\u5206\u5269\u4f59\u7a7a\u95f4 *\/\n\t\/* \u5982\u679c\u4e09\u4e2a\u4f38\u7f29\u9879\u76ee\u503c\u4e3a1,2,3\uff0c\u5206\u522b\u5206\u52301\/6\u30012\/6\u30013\/6\u7684\u5269\u4f59\u7a7a\u95f4 *\/\n\t\/* \u5982\u679c\u6709\u6362\u884c\uff0c\u6309\u65b0\u884c\u62c9\u4f38 *\/\n\tflex-grow: 1;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e3b\u8f74\u538b\u7f29<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.child {\n\t\/* \u9ed8\u8ba4\u503c\u662f1\uff0c\u7b49\u6bd4\u4f8b\u7f29\u5c0f *\/\n\t\/* \u5982\u679c\u4e09\u4e2a\u4f38\u7f29\u9879\u76ee\u5bbd\u4e3a200\u3001300\u3001200\uff0c\u503c\u4e3a1,2,3\uff0c\u5219 *\/\n\t\/* \u8ba1\u7b97\u5206\u6bcd\uff1a(200 * 1) + (300 * 2) + (200 * 3) = 1400 *\/\n\t\/* \u8ba1\u7b97\u6bd4\u4f8b\uff1a *\/\n\t\/* \u9879\u76ee\u4e00\uff1a(200 * 1) \/ 1400 = \u6bd4\u4f8b\u503c1 *\/\n\t\/* \u9879\u76ee\u4e8c\uff1a(300 * 2) \/ 1400 = \u6bd4\u4f8b\u503c2 *\/\n\t\/* \u9879\u76ee\u4e09\uff1a(200 * 3) \/ 1400 = \u6bd4\u4f8b\u503c3 *\/\n\t\/* \u6700\u7ec8\u6536\u7f29\u5927\u5c0f\uff1a *\/\n\t\/* \u9879\u76ee\u4e00\u6536\u7f29\uff1a\u6bd4\u4f8b\u503c1 * 200 *\/\n\t\/* \u9879\u76ee\u4e8c\u6536\u7f29\uff1a\u6bd4\u4f8b\u503c2 * 300 *\/\n\t\/* \u9879\u76ee\u4e09\u6536\u7f29\uff1a\u6bd4\u4f8b\u503c3 * 200 *\/\n\tflex-shrink: 1;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>flex\u590d\u5408\u5c5e\u6027<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.child {\n\t\/* \u53ef\u4ee5\u62c9\u4f38 \u53ef\u4ee5\u538b\u7f29 \u4e0d\u8bbe\u7f6e\u57fa\u51c6\u957f\u5ea6\uff0c\u53ef\u7b80\u5199\uff1aflex: auto; *\/\n\tflex: 1 1 auto;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6392\u5e8f\u548c\u5355\u72ec\u5bf9\u9f50<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.child {\n\t\/* \u9875\u9762\u6309\u7167\u8fd9\u4e2a\u503c\u5f80\u4e3b\u8f74\u65b9\u5411\u6392\u5e8f\uff0c\u6570\u503c\u8d8a\u5c0f\u8d8a\u9760\u524d\uff08\u9ed8\u8ba40\uff09 *\/\n\torder: -1;\n}\n.child {\n\t\/* \u4fa7\u8f74\u5355\u72ec\u5bf9\u9f50\uff08\u4e86\u89e3\u5373\u53ef\uff09 *\/\n\talign-self: center;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>**\u5f53\u7236\u5143\u7d20\u6ca1\u6709\u9ad8\u5ea6\u65f6\u5b50\u5143\u7d20\u6c34\u5e73\u5782\u76f4\u5c45\u4e2d\uff1a**<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.father {\n\t\/* \u5148\u8ba1\u7b97\u7236\u5143\u7d20\u7684\u9ad8\u5ea6 *\/\n\t\/* 100vh\uff1a\u6574\u4e2a\u9875\u9762\u9ad8\u5ea6 *\/\n\t\/* 70px\uff1a\u4e0a\u65b9\u5bfc\u822a\u6761\u7684\u9ad8\u5ea6 *\/\n\theight: calc(100vh - 70px);\n}\n.child {\n\t\/* \u5b50\u5143\u7d20\u4f7f\u7528margin: auto;\u5b9e\u73b0\u6c34\u5e73\u5782\u76f4\u5c45\u4e2d *\/\n\t\/* margin: auto;\u5fc5\u987b\u7236\u5143\u7d20\u6709\u9ad8\u5ea6 *\/\n\tmargin: auto;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5143\u7d20\u8bbe\u7f6e\u4e3a\u4f38\u7f29\u5bb9\u5668\uff08\u5f00\u542fflex\u5e03\u5c40\uff09\uff08\u7236\u5bb9\u5668\u5199\u6837\u5f0f\uff09 **\u6539\u53d8\u4e86\u4e3b\u8f74\u65b9\u5411\uff0c\u4fa7\u8f74\u4e5f\u968f\u4e4b\u6539\u53d8** \u4e3b\u8f74\u5bf9\u9f50\u65b9\u5f0f\uff08 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[13,11],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-6","tag-css","tag-11"],"_links":{"self":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":1,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions\/80"}],"wp:attachment":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}