{"id":26882,"date":"2024-11-24T17:22:38","date_gmt":"2024-11-24T09:22:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26882\/"},"modified":"2024-11-24T17:22:38","modified_gmt":"2024-11-24T09:22:38","slug":"%e7%a7%bb%e5%8a%a8%e7%ab%af-css-%e5%b0%8f%e6%a0%87%e7%ad%be%e5%9e%82%e7%9b%b4%e5%af%b9%e9%bd%90%e9%9a%be%e9%a2%98%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-flex-%e5%b8%83%e5%b1%80%e5%92%8c-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26882\/","title":{"rendered":"\u79fb\u52a8\u7aef CSS \u5c0f\u6807\u7b7e\u5782\u76f4\u5bf9\u9f50\u96be\u9898\uff1a\u5982\u4f55\u89e3\u51b3 flex \u5e03\u5c40\u548c\u7edd\u5bf9\u5e03\u5c40\u4e0b\u7684\u5bf9\u9f50\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173111978074626.jpg\" class=\"aligncenter\" title=\"\u79fb\u52a8\u7aef CSS \u5c0f\u6807\u7b7e\u5782\u76f4\u5bf9\u9f50\u96be\u9898\uff1a\u5982\u4f55\u89e3\u51b3 flex \u5e03\u5c40\u548c\u7edd\u5bf9\u5e03\u5c40\u4e0b\u7684\u5bf9\u9f50\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"\u79fb\u52a8\u7aef CSS \u5c0f\u6807\u7b7e\u5782\u76f4\u5bf9\u9f50\u96be\u9898\uff1a\u5982\u4f55\u89e3\u51b3 flex \u5e03\u5c40\u548c\u7edd\u5bf9\u5e03\u5c40\u4e0b\u7684\u5bf9\u9f50\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u79fb\u52a8\u7aef  \u5c0f\u6807\u7b7e\u5782\u76f4\u5bf9\u9f50\u96be\u9898<\/strong><\/p>\n<p>\u5c0f\u6807\u7b7e\u6548\u679c\u662f\u8bbe\u8ba1\u7a3f\u4e2d\u5e38\u89c1\u7684\u5143\u7d20\uff0c\u4f46\u5728\u79fb\u52a8\u7aef\u8fd8\u539f\u8fd9\u7c7b\u6548\u679c\u65f6\uff0c\u5e38\u5e38\u4f1a\u9047\u5230\u5782\u76f4\u5bf9\u9f50\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e24\u79cd\u53ef\u884c\u7684\u65b9\u5f0f\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<p><strong>flex \u5e03\u5c40<\/strong><\/p>\n<pre>.tag {\n  display: flex;\n  justify-content: center; \/* \u6c34\u5e73\u5c45\u4e2d *\/\n  align-items: center; \/* \u5782\u76f4\u5c45\u4e2d *\/\n  line-height: normal; \/* \u5728\u67d0\u4e9b\u5b89\u5353\u4e0b\uff0c\u5782\u76f4\u5c45\u4e2d *\/\n  border: 1px solid red;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>flex \u5e03\u5c40\u901a\u8fc7 justify-content \u548c align-items \u5c5e\u6027\u5206\u522b\u63a7\u5236\u6c34\u5e73\u548c\u5782\u76f4\u5bf9\u9f50\uff0c\u5e76\u901a\u8fc7 line-height \u5c5e\u6027\u4fee\u590d\u67d0\u4e9b\u5b89\u5353\u8bbe\u5907\u4e0a\u7684\u5782\u76f4\u5bf9\u9f50\u95ee\u9898\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u7edd\u5bf9\u5e03\u5c40<\/strong><\/p>\n<pre>.tag {\n  position: relative;\n  border: 1px solid red;\n}\n.text {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  transform: translate(-50%,-50%);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7edd\u5bf9\u5e03\u5c40\u901a\u8fc7\u5728\u7236\u5143\u7d20\u4e0a\u8bbe\u7f6e position \u5c5e\u6027\u4e3a relative\uff0c\u5e76\u5728\u5b50\u5143\u7d20\u4e0a\u8bbe\u7f6e position \u5c5e\u6027\u4e3a absolute\uff0c\u7136\u540e\u4f7f\u7528 left \u548c top \u5c5e\u6027\u5c06\u5b50\u5143\u7d20\u5b9a\u4f4d\u5230\u7236\u5143\u7d20\u7684\u4e2d\u5fc3\u3002\u6700\u540e\uff0c\u4f7f\u7528 transform \u5c5e\u6027\u8fdb\u884c\u5e73\u79fb\uff0c\u5b9e\u73b0\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u79fb\u52a8\u7aef CSS \u5c0f\u6807\u7b7e\u5782\u76f4\u5bf9\u9f50\u96be\u9898\uff1a\u5982\u4f55\u89e3\u51b3 flex \u5e03\u5c40\u548c\u7edd\u5bf9\u5e03\u5c40\u4e0b\u7684\u5bf9\u9f50\u95ee\u9898\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>\u79fb\u52a8\u7aef \u5c0f\u6807\u7b7e\u5782\u76f4\u5bf9\u9f50\u96be\u9898 \u5c0f\u6807\u7b7e\u6548\u679c\u662f\u8bbe\u8ba1\u7a3f\u4e2d\u5e38\u89c1\u7684\u5143\u7d20\uff0c\u4f46\u5728\u79fb\u52a8\u7aef\u8fd8\u539f\u8fd9\u7c7b\u6548\u679c\u65f6\uff0c\u5e38\u5e38\u4f1a\u9047\u5230\u5782\u76f4\u5bf9\u9f50\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e24\u79cd\u53ef\u884c\u7684\u65b9\u5f0f\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002 flex \u5e03\u5c40 .tag { display: flex; justify-content: center; \/* \u6c34\u5e73\u5c45\u4e2d *\/ align-items: center; \/* \u5782\u76f4\u5c45\u4e2d *\/ line-height: normal; \/* \u5728\u67d0\u4e9b\u5b89\u5353\u4e0b\uff0c\u5782\u76f4\u5c45\u4e2d *\/ border: 1px solid red; } \u767b\u5f55\u540e\u590d\u5236 flex \u5e03\u5c40\u901a\u8fc7 justify-content \u548c align-items \u5c5e\u6027\u5206\u522b\u63a7\u5236\u6c34\u5e73\u548c\u5782\u76f4\u5bf9\u9f50\uff0c\u5e76\u901a\u8fc7 line-height \u5c5e\u6027\u4fee\u590d\u67d0\u4e9b\u5b89\u5353\u8bbe\u5907\u4e0a\u7684\u5782\u76f4\u5bf9\u9f50\u95ee\u9898\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u7edd\u5bf9\u5e03\u5c40 .tag { position: relative; border: 1px solid red; } .text { position: absolute; left: 50%; [&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-26882","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26882","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=26882"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26882\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}