{"id":588,"date":"2024-12-28T17:48:14","date_gmt":"2024-12-28T09:48:14","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=588"},"modified":"2024-12-28T17:48:14","modified_gmt":"2024-12-28T09:48:14","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e8%a7%86%e5%8f%a3%e5%8d%95%e4%bd%8d%e6%9d%a5%e7%a1%ae%e4%bf%9d-css-%e4%b8%ad%e7%9a%84%e5%93%8d%e5%ba%94%e5%bc%8f%e5%ad%97%e4%bd%93%e5%a4%a7%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/28\/%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e8%a7%86%e5%8f%a3%e5%8d%95%e4%bd%8d%e6%9d%a5%e7%a1%ae%e4%bf%9d-css-%e4%b8%ad%e7%9a%84%e5%93%8d%e5%ba%94%e5%bc%8f%e5%ad%97%e4%bd%93%e5%a4%a7%e5%b0%8f\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u89c6\u53e3\u5355\u4f4d\u6765\u786e\u4fdd CSS \u4e2d\u7684\u54cd\u5e94\u5f0f\u5b57\u4f53\u5927\u5c0f"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u89c6\u53e3\u5355\u4f4d\uff08<code>vw<\/code>, <code>vh<\/code>, <code>vmin<\/code>, <code>vmax<\/code>\uff09\u662f CSS \u4e2d\u975e\u5e38\u6709\u7528\u7684\u5355\u4f4d\uff0c\u7279\u522b\u662f\u5728\u5b9e\u73b0\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u65f6\u3002\u5b83\u4eec\u662f\u76f8\u5bf9\u4e8e\u89c6\u53e3\uff08viewport\uff09\u5927\u5c0f\u7684\u5355\u4f4d\uff0c\u53ef\u4ee5\u5e2e\u52a9\u786e\u4fdd\u5b57\u4f53\u5927\u5c0f\u6839\u636e\u5c4f\u5e55\u5c3a\u5bf8\u81ea\u52a8\u8c03\u6574\u3002\u4e0b\u9762\u662f\u5982\u4f55\u4f7f\u7528\u89c6\u53e3\u5355\u4f4d\u6765\u786e\u4fdd CSS \u4e2d\u7684\u54cd\u5e94\u5f0f\u5b57\u4f53\u5927\u5c0f\u7684\u51e0\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u4f7f\u7528 <code>vw<\/code>\uff08\u89c6\u53e3\u5bbd\u5ea6\uff09\u5355\u4f4d\u8bbe\u7f6e\u5b57\u4f53\u5927\u5c0f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>vw<\/code>\uff08\u89c6\u53e3\u5bbd\u5ea6\uff09\u5355\u4f4d\u7684\u503c\u662f\u76f8\u5bf9\u4e8e\u89c6\u53e3\u5bbd\u5ea6\u7684 1% \u8ba1\u7b97\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c <code>1vw = 1%<\/code> \u7684\u89c6\u53e3\u5bbd\u5ea6\uff0c\u5219\u5f53\u89c6\u53e3\u5bbd\u5ea6\u4e3a 1000px \u65f6\uff0c<code>1vw<\/code> \u7b49\u4e8e 10px\u3002\u901a\u8fc7\u4f7f\u7528 <code>vw<\/code> \u5355\u4f4d\uff0c\u4f60\u53ef\u4ee5\u8ba9\u5b57\u4f53\u5927\u5c0f\u968f\u5c4f\u5e55\u5bbd\u5ea6\u53d8\u5316\u800c\u81ea\u52a8\u8c03\u6574\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\n    font-size: 5vw; \/* \u5b57\u4f53\u5927\u5c0f\u662f\u89c6\u53e3\u5bbd\u5ea6\u7684 5% *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u89c6\u53e3\u5bbd\u5ea6\u662f 1000px\uff0c\u90a3\u4e48 <code>5vw<\/code> \u5c31\u662f 50px\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u89c6\u53e3\u5bbd\u5ea6\u53d8\u4e3a 500px\uff0c\u90a3\u4e48 <code>5vw<\/code> \u5c31\u53d8\u6210 25px\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\uff0c\u5b57\u4f53\u5927\u5c0f\u4f1a\u968f\u7740\u5c4f\u5e55\u5bbd\u5ea6\u7684\u53d8\u5316\u800c\u52a8\u6001\u8c03\u6574\uff0c\u8fbe\u5230\u54cd\u5e94\u5f0f\u6548\u679c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u7ed3\u5408 <code>vw<\/code> \u548c <code>rem<\/code> \u5355\u4f4d\u521b\u5efa\u66f4\u7075\u6d3b\u7684\u5b57\u4f53\u5927\u5c0f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136 <code>vw<\/code> \u5355\u4f4d\u5f88\u65b9\u4fbf\uff0c\u4f46\u5f53\u5c4f\u5e55\u975e\u5e38\u5927\u6216\u975e\u5e38\u5c0f\u65f6\uff0c\u5b57\u4f53\u53ef\u80fd\u4f1a\u53d8\u5f97\u8fc7\u5927\u6216\u8fc7\u5c0f\uff0c\u56e0\u6b64\u5efa\u8bae\u7ed3\u5408\u4f7f\u7528 <code>rem<\/code> \u548c <code>vw<\/code>\uff0c\u5e76\u901a\u8fc7 <code>calc()<\/code> \u51fd\u6570\u8fdb\u884c\u8c03\u8282\u3002\u8fd9\u6837\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u6700\u5c0f\u548c\u6700\u5927\u5b57\u4f53\u5927\u5c0f\u8303\u56f4\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\n    font-size: calc(1rem + 5vw); \/* \u57fa\u7840\u5b57\u4f53\u5927\u5c0f + \u968f\u89c6\u53e3\u5bbd\u5ea6\u53d8\u5316\u7684\u6bd4\u4f8b *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>1rem<\/code> \u662f\u6839\u5143\u7d20\u7684\u5b57\u4f53\u5927\u5c0f\uff08\u901a\u5e38\u4e3a 16px\uff09\uff0c\u8fd9\u4fdd\u8bc1\u4e86\u5728\u5c0f\u5c4f\u5e55\u8bbe\u5907\u4e0a\u5b57\u4f53\u4e0d\u4f1a\u592a\u5c0f\u3002<\/li>\n\n\n\n<li><code>5vw<\/code> \u662f\u54cd\u5e94\u5f0f\u90e8\u5206\uff0c\u57fa\u4e8e\u89c6\u53e3\u5bbd\u5ea6\u52a8\u6001\u53d8\u5316\u3002<\/li>\n\n\n\n<li><code>calc()<\/code> \u8ba9\u4f60\u5728\u9759\u6001\u548c\u54cd\u5e94\u5f0f\u90e8\u5206\u4e4b\u95f4\u8fdb\u884c\u52a0\u6cd5\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u4f7f\u7528 <code>clamp()<\/code> \u51fd\u6570\u9650\u5236\u5b57\u4f53\u5927\u5c0f\u7684\u8303\u56f4<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u907f\u514d\u5b57\u4f53\u8fc7\u5927\u6216\u8fc7\u5c0f\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 CSS <code>clamp()<\/code> \u51fd\u6570\u6765\u8bbe\u5b9a\u6700\u5c0f\u503c\u3001\u7406\u60f3\u503c\u548c\u6700\u5927\u503c\u3002<code>clamp()<\/code> \u51fd\u6570\u5141\u8bb8\u4f60\u6307\u5b9a\u4e00\u4e2a\u503c\u8303\u56f4\uff0c\u4f7f\u5b57\u4f53\u5927\u5c0f\u5728\u6b64\u8303\u56f4\u5185\u968f\u89c6\u53e3\u53d8\u5316\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\n    font-size: clamp(24px, 5vw, 48px);\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>clamp(24px, 5vw, 48px)<\/code> \u8868\u793a\u5b57\u4f53\u5927\u5c0f\u4f1a\u968f\u7740\u89c6\u53e3\u5bbd\u5ea6\u53d8\u5316\uff0c\u4f46\u59cb\u7ec8\u4f1a\u5728 24px \u5230 48px \u4e4b\u95f4\u3002<\/li>\n\n\n\n<li><code>24px<\/code> \u662f\u6700\u5c0f\u5b57\u4f53\u5927\u5c0f\u3002<\/li>\n\n\n\n<li><code>5vw<\/code> \u662f\u7406\u60f3\u5b57\u4f53\u5927\u5c0f\uff08\u57fa\u4e8e\u89c6\u53e3\u5bbd\u5ea6\uff09\u3002<\/li>\n\n\n\n<li><code>48px<\/code> \u662f\u6700\u5927\u5b57\u4f53\u5927\u5c0f\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u786e\u4fdd\u5728\u4e0d\u540c\u8bbe\u5907\u548c\u5c4f\u5e55\u5c3a\u5bf8\u4e0b\uff0c\u5b57\u4f53\u59cb\u7ec8\u4fdd\u6301\u9002\u5f53\u7684\u5927\u5c0f\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u4f7f\u7528 <code>vh<\/code>\uff08\u89c6\u53e3\u9ad8\u5ea6\uff09\u5355\u4f4d\u8bbe\u7f6e\u5b57\u4f53\u5927\u5c0f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86 <code>vw<\/code>\uff0c\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>vh<\/code>\uff08\u89c6\u53e3\u9ad8\u5ea6\uff09\u5355\u4f4d\uff0c\u7279\u522b\u662f\u5f53\u4f60\u5e0c\u671b\u5b57\u4f53\u5927\u5c0f\u4e0e\u5c4f\u5e55\u9ad8\u5ea6\u6210\u6bd4\u4f8b\u65f6\u3002<code>1vh<\/code> \u7b49\u4e8e\u89c6\u53e3\u9ad8\u5ea6\u7684 1%\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\n    font-size: 10vh; \/* \u5b57\u4f53\u5927\u5c0f\u662f\u89c6\u53e3\u9ad8\u5ea6\u7684 10% *\/\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>10vh<\/code> \u5b57\u4f53\u5927\u5c0f\u662f\u89c6\u53e3\u9ad8\u5ea6\u7684 10%\u3002\u8fd9\u79cd\u65b9\u6cd5\u5e38\u7528\u4e8e\u7eb5\u5411\u5e03\u5c40\u548c\u5c4f\u5e55\u9ad8\u5ea6\u76f8\u5173\u7684\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u7ed3\u5408 <code>min-width<\/code> \u548c <code>max-width<\/code> \u5a92\u4f53\u67e5\u8be2\u8c03\u6574\u5b57\u4f53\u5927\u5c0f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136 <code>vw<\/code> \u5355\u4f4d\u80fd\u591f\u5f88\u597d\u5730\u5904\u7406\u5927\u90e8\u5206\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u9700\u6c42\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7ed3\u5408\u5a92\u4f53\u67e5\u8be2\u6765\u9650\u5236\u5b57\u4f53\u5927\u5c0f\u7684\u53d8\u5316\u8303\u56f4\u53ef\u80fd\u66f4\u5408\u9002\u3002\u901a\u8fc7\u5728\u7279\u5b9a\u7684\u5c4f\u5e55\u5bbd\u5ea6\u8303\u56f4\u5185\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\uff0c\u53ef\u4ee5\u4f7f\u5f97\u5b57\u4f53\u5927\u5c0f\u66f4\u4e3a\u53ef\u63a7\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\n    font-size: 5vw; \/* \u57fa\u672c\u54cd\u5e94\u5f0f\u5b57\u4f53 *\/\n}\n\n@media (max-width: 768px) {\n    h1 {\n        font-size: 8vw; \/* \u5c0f\u5c4f\u5e55\u8bbe\u5907\u65f6\uff0c\u589e\u5927\u5b57\u4f53 *\/\n    }\n}\n\n@media (max-width: 480px) {\n    h1 {\n        font-size: 10vw; \/* \u66f4\u5c0f\u7684\u5c4f\u5e55\uff0c\u8fdb\u4e00\u6b65\u589e\u5927\u5b57\u4f53 *\/\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u5927\u5c4f\u5e55\u4e0a\uff0c<code>h1<\/code> \u7684\u5b57\u4f53\u5927\u5c0f\u662f\u89c6\u53e3\u5bbd\u5ea6\u7684 5%\u3002<\/li>\n\n\n\n<li>\u5728\u5c0f\u4e8e 768px \u7684\u5c4f\u5e55\u4e0a\uff0c\u5b57\u4f53\u5927\u5c0f\u53d8\u4e3a 8vw\uff0c\u8fdb\u4e00\u6b65\u589e\u52a0\u5b57\u4f53\u5927\u5c0f\u3002<\/li>\n\n\n\n<li>\u5728\u5c0f\u4e8e 480px \u7684\u5c4f\u5e55\u4e0a\uff0c\u5b57\u4f53\u5927\u5c0f\u53d8\u4e3a 10vw\uff0c\u786e\u4fdd\u5728\u5c0f\u5c4f\u5e55\u4e0a\u5b57\u4f53\u6e05\u6670\u53ef\u8bfb\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u786e\u4fdd\u54cd\u5e94\u5f0f\u5b57\u4f53\u5927\u5c0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>vw<\/code> \u5355\u4f4d<\/strong>\uff1a\u4f7f\u5b57\u4f53\u5927\u5c0f\u57fa\u4e8e\u89c6\u53e3\u5bbd\u5ea6\u7684\u767e\u5206\u6bd4\u3002<\/li>\n\n\n\n<li><strong><code>calc()<\/code> \u548c <code>rem<\/code><\/strong>\uff1a\u7ed3\u5408\u9759\u6001\u548c\u52a8\u6001\u5b57\u4f53\u5927\u5c0f\uff0c\u786e\u4fdd\u5b57\u4f53\u5728\u5927\u548c\u5c0f\u5c4f\u5e55\u4e0a\u90fd\u5408\u9002\u3002<\/li>\n\n\n\n<li><strong><code>clamp()<\/code> \u51fd\u6570<\/strong>\uff1a\u5728\u6307\u5b9a\u8303\u56f4\u5185\u52a8\u6001\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\uff0c\u907f\u514d\u5b57\u4f53\u8fc7\u5927\u6216\u8fc7\u5c0f\u3002<\/li>\n\n\n\n<li><strong><code>vh<\/code> \u5355\u4f4d<\/strong>\uff1a\u6839\u636e\u89c6\u53e3\u9ad8\u5ea6\u8bbe\u7f6e\u5b57\u4f53\u5927\u5c0f\uff0c\u9002\u7528\u4e8e\u9ad8\u5ea6\u76f8\u5173\u7684\u8bbe\u8ba1\u3002<\/li>\n\n\n\n<li><strong>\u5a92\u4f53\u67e5\u8be2<\/strong>\uff1a\u6839\u636e\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\uff0c\u786e\u4fdd\u5b57\u4f53\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u90fd\u80fd\u9002\u5e94\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u7ed3\u5408 <code>vw<\/code> \u548c <code>clamp()<\/code>\uff0c\u8fd9\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u7075\u6d3b\u4e14\u53ef\u9760\u7684\u54cd\u5e94\u5f0f\u5b57\u4f53\u5927\u5c0f\uff0c\u540c\u65f6\u907f\u514d\u8fc7\u5927\u6216\u8fc7\u5c0f\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89c6\u53e3\u5355\u4f4d\uff08vw, vh, vmin, vmax\uff09\u662f CSS \u4e2d\u975e\u5e38\u6709\u7528\u7684\u5355\u4f4d\uff0c\u7279\u522b\u662f\u5728\u5b9e\u73b0\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u65f6\u3002\u5b83\u4eec\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-588","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=588"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/588\/revisions"}],"predecessor-version":[{"id":589,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/588\/revisions\/589"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}