{"id":1028,"date":"2023-03-12T09:38:51","date_gmt":"2023-03-12T01:38:51","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1028"},"modified":"2023-04-29T13:12:55","modified_gmt":"2023-04-29T05:12:55","slug":"html5-mobile-page-adaptive-mobile-screen-method","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/html5-mobile-page-adaptive-mobile-screen-method\/","title":{"rendered":"HTML5\u79fb\u52a8\u9875\u9762\u81ea\u9002\u5e94\u624b\u673a\u5c4f\u5e55\u65b9\u6cd5"},"content":{"rendered":"<h2>\u4f7f\u7528meta\u6807\u7b7e\uff1aviewport<\/h2>\n<p>H5\u79fb\u52a8\u7aef\u9875\u9762\u81ea\u9002\u5e94\u666e\u904d\u4f7f\u7528\u7684\u65b9\u6cd5\uff0c\u7406\u8bba\u4e0a\u8bb2\u4f7f\u7528\u8fd9\u4e2a\u6807\u7b7e\u662f\u53ef\u4ee5\u9002\u5e94\u6240\u6709\u5c3a\u5bf8\u7684\u5c4f\u5e55\u7684\uff0c\u4f46\u662f\u5404\u8bbe\u5907\u5bf9\u8be5\u6807\u7b7e\u7684\u89e3\u91ca\u65b9\u5f0f\u53ca\u652f\u6301\u7a0b\u5ea6\u4e0d\u540c\u9020\u6210\u4e86\u4e0d\u80fd\u517c\u5bb9\u6240\u6709\u6d4f\u89c8\u5668\u6216\u7cfb\u7edf\u3002<\/p>\n<p><!-- more --><\/p>\n<p>viewport \u662f\u7528\u6237\u7f51\u9875\u7684\u53ef\u89c6\u533a\u57df\u3002\u7ffb\u8bd1\u4e3a\u4e2d\u6587\u53ef\u4ee5\u53eb\u505a&quot;\u89c6\u533a&quot;\u3002<\/p>\n<p>\u624b\u673a\u6d4f\u89c8\u5668\u662f\u628a\u9875\u9762\u653e\u5728\u4e00\u4e2a\u865a\u62df\u7684&quot;\u7a97\u53e3&quot;\uff08viewport\uff09\u4e2d\uff0c\u901a\u5e38\u8fd9\u4e2a\u865a\u62df\u7684&quot;\u7a97\u53e3&quot;\uff08viewport\uff09\u6bd4\u5c4f\u5e55\u5bbd\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u628a\u6bcf\u4e2a\u7f51\u9875\u6324\u5230\u5f88\u5c0f\u7684\u7a97\u53e3\u4e2d\uff08\u8fd9\u6837\u4f1a\u7834\u574f\u6ca1\u6709\u9488\u5bf9\u624b\u673a\u6d4f\u89c8\u5668\u4f18\u5316\u7684\u7f51\u9875\u7684\u5e03\u5c40\uff09\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u5e73\u79fb\u548c\u7f29\u653e\u6765\u770b\u7f51\u9875\u7684\u4e0d\u540c\u90e8\u5206\u3002<\/p>\n<p>viewport\u6807\u7b7e\u6781\u5176\u5c5e\u6027\uff1a<\/p>\n<pre><code class=\"language-html\">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot;&gt;<\/code><\/pre>\n<p>\u6bcf\u4e2a\u5c5e\u6027\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u5c5e\u6027\u540d<\/th>\n<th style=\"text-align: center;\">\u53d6\u503c<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">width<\/td>\n<td style=\"text-align: center;\">\u6b63\u6574\u6570 \u6216 device-width<\/td>\n<td style=\"text-align: center;\">\u5b9a\u4e49\u89c6\u53e3\u7684\u5bbd\u5ea6\uff0c\u5355\u4f4d\u4e3a\u50cf\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">height<\/td>\n<td style=\"text-align: center;\">\u6b63\u6574\u6570 \u6216 device-height<\/td>\n<td style=\"text-align: center;\">\u5b9a\u4e49\u89c6\u53e3\u7684\u9ad8\u5ea6\uff0c\u5355\u4f4d\u4e3a\u50cf\u7d20\uff0c\u4e00\u822c\u4e0d\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">initial-scale<\/td>\n<td style=\"text-align: center;\">[0.0-10.0]<\/td>\n<td style=\"text-align: center;\">\u5b9a\u4e49\u521d\u59cb\u7f29\u653e\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">minimum-scale<\/td>\n<td style=\"text-align: center;\">[0.0-10.0]<\/td>\n<td style=\"text-align: center;\">\u5b9a\u4e49\u7f29\u5c0f\u6700\u5c0f\u6bd4\u4f8b\uff0c\u5b83\u5fc5\u987b\u5c0f\u4e8e\u6216\u7b49\u4e8emaximum-scale\u8bbe\u7f6e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">maximum-scale<\/td>\n<td style=\"text-align: center;\">[0.0-10.0]<\/td>\n<td style=\"text-align: center;\">\u5b9a\u4e49\u653e\u5927\u6700\u5927\u6bd4\u4f8b\uff0c\u5b83\u5fc5\u987b\u5927\u4e8e\u6216\u7b49\u4e8eminimum-scale\u8bbe\u7f6e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">user-scalable<\/td>\n<td style=\"text-align: center;\">yes\/no<\/td>\n<td style=\"text-align: center;\">\u5b9a\u4e49\u662f\u5426\u5141\u8bb8\u7528\u6237\u624b\u52a8\u7f29\u653e\u9875\u9762\uff0c\u9ed8\u8ba4\u503cyes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;meta charset=&quot;utf-8&quot;&gt;\n    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot;&gt;\n    &lt;meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot;&gt;\n    &lt;meta name=&quot;apple-mobile-web-app-status-bar-style&quot; content=&quot;black&quot;&gt;\n    &lt;meta name=&quot;format-detection&quot; content=&quot;telephone=no&quot;&gt;\n    &lt;link rel=&quot;dns-prefetch&quot; href=&quot;\/\/www.appblog.cn&quot;\/&gt;\n    &lt;title&gt;APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;div id=&quot;app&quot;&gt;&lt;\/div&gt;\n    &lt;!-- built files will be auto injected --&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h2>\u4f7f\u7528CSS3\u5355\u4f4drem<\/h2>\n<p>rem\u662fCSS3\u65b0\u589e\u7684\u4e00\u4e2a\u76f8\u5bf9\u5355\u4f4d\uff08root em\uff0c\u6839em\uff09\uff0c\u4f7f\u7528rem\u4e3a\u5143\u7d20\u8bbe\u5b9a\u5b57\u4f53\u5927\u5c0f\u65f6\uff0c\u662f\u76f8\u5bf9\u5927\u5c0f\uff0c\u4f46\u76f8\u5bf9\u7684\u53ea\u662fHTML\u6839\u5143\u7d20\u3002\u901a\u8fc7\u5b83\u65e2\u53ef\u4ee5\u505a\u5230\u53ea\u4fee\u6539\u6839\u5143\u7d20\u5c31\u6210\u6bd4\u4f8b\u5730\u8c03\u6574\u6240\u6709\u5b57\u4f53\u5927\u5c0f\uff0c\u53c8\u53ef\u4ee5\u907f\u514d\u5b57\u4f53\u5927\u5c0f\u9010\u5c42\u590d\u5408\u7684\u8fde\u9501\u53cd\u5e94\u3002<\/p>\n<p>\u76ee\u524d\uff0c\u9664\u4e86IE8\u53ca\u66f4\u65e9\u7248\u672c\u5916\uff0c\u6240\u6709\u6d4f\u89c8\u5668\u5747\u5df2\u652f\u6301rem\u3002\u5bf9\u4e8e\u4e0d\u652f\u6301\u5b83\u7684\u6d4f\u89c8\u5668\u591a\u5199\u4e00\u4e2a\u7edd\u5bf9\u5355\u4f4d\u7684\u58f0\u660e\u3002\u8fd9\u4e9b\u6d4f\u89c8\u5668\u4f1a\u5ffd\u7565\u7528rem\u8bbe\u5b9a\u7684\u5b57\u4f53\u5927\u5c0f\u3002\u4e0b\u9762\u5c31\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-css\">p {font-size:14px; font-size:.875rem;}<\/code><\/pre>\n<p>\u9ed8\u8ba4html\u7684font-size\u662f16px\uff0c\u53731rem=16px\uff0c\u5982\u679c\u67d0div\u5bbd\u5ea6\u4e3a32px\u4f60\u53ef\u4ee5\u8bbe\u4e3a2rem\u3002<\/p>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u4e3a\u4e86\u4fbf\u4e8e\u8ba1\u7b97\u6570\u503c\u5219\u4f7f\u752862.5%\uff0c\u5373\u9ed8\u8ba4\u768410px\u4f5c\u4e3a\u57fa\u6570\u3002\u5f53\u7136\u8fd9\u4e2a\u57fa\u6570\u53ef\u4ee5\u4e3a\u4efb\u4f55\u6570\u503c\uff0c\u89c6\u5177\u4f53\u60c5\u51b5\u800c\u5b9a\u3002\u8bbe\u7f6e\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>html {font-size:62.5%(10\/16*100%)}<\/code><\/pre>\n<p>\u5177\u4f53\u4e0d\u540c\u5c4f\u5e55\u4e0b\u7684\u89c4\u5219\u5b9a\u4e49\uff0c\u5373\u57fa\u6570\u7684\u5b9a\u4e49\u65b9\u5f0f\uff1a\u53ef\u4ee5\u901a\u8fc7CSS\u5b9a\u4e49\uff0c\u4e0d\u540c\u5bbd\u5ea6\u8303\u56f4\u91cc\u5b9a\u4e49\u4e0d\u540c\u7684\u57fa\u6570\u503c\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u901a\u8fc7js\u4e00\u6b21\u5b9a\u4e49\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">&lt;script type=&quot;text\/javascript&quot;&gt;\n(function (doc, win) {\n  var docEl = doc.documentElement,\n  resizeEvt = &#039;orientationchange&#039; in window ? &#039;orientationchange&#039; : &#039;resize&#039;,\n  recalc = function () {\n    var clientWidth = docEl.clientWidth;\n    if (!clientWidth) return;\n    docEl.style.fontSize = 20 * (clientWidth \/ 320) + &#039;px&#039;;  \/\/\u5176\u4e2d\u201c20\u201d\u6839\u636e\u4f60\u8bbe\u7f6e\u7684html\u7684font-size\u5c5e\u6027\u503c\u505a\u9002\u5f53\u7684\u53d8\u5316\n  };\n\n  if (!doc.addEventListener) return;\n  win.addEventListener(resizeEvt, recalc, false);\n  doc.addEventListener(&#039;DOMContentLoaded&#039;, recalc, false);\n})(document, window);\n&lt;\/script&gt;<\/code><\/pre>\n<h2>\u4f7f\u7528\u5a92\u4f53\u67e5\u8be2<\/h2>\n<p>\u5a92\u4f53\u67e5\u8be2\u4e5f\u662fCSS3\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u8981\u89e3\u51b3\u7684\u95ee\u9898\u662f\u9002\u5e94\u624b\u673a\u5c4f\u5e55\uff0c\u8fd9\u4e2a\u5a92\u4f53\u67e5\u8be2\u6b63\u662f\u4e3a\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u800c\u751f\u3002<\/p>\n<p>\u5a92\u4f53\u67e5\u8be2\u7684\u529f\u80fd\u5c31\u662f\u4e3a\u4e0d\u540c\u7684\u5a92\u4f53\u8bbe\u7f6e\u4e0d\u540c\u7684CSS\u6837\u5f0f\uff0c\u8fd9\u91cc\u7684\u201c\u5a92\u4f53\u201d\u5305\u62ec\u9875\u9762\u5c3a\u5bf8\uff0c\u8bbe\u5907\u5c4f\u5e55\u5c3a\u5bf8\u7b49\u3002<\/p>\n<p>\u4f8b\u5982\uff1a\u5982\u679c\u6d4f\u89c8\u5668\u7a97\u53e3\u5c0f\u4e8e 500px, \u80cc\u666f\u5c06\u53d8\u4e3a\u6d45\u84dd\u8272\uff1a<\/p>\n<pre><code class=\"language-css\">@media only screen and (max-width: 500px) {\n    body {\n        background-color: lightblue;\n    }\n}<\/code><\/pre>\n<h2>\u4f7f\u7528\u767e\u5206\u6bd4<\/h2>\n<p>\u767e\u5206\u6bd4\u6307\u7684\u662f\u7236\u5143\u7d20\uff0c\u6240\u6709\u767e\u5206\u6bd4\u90fd\u662f\u8fd9\u6837\u7684\u3002\u5b50\u5143\u7d20\u5bbd\u5ea650%\uff0c\u90a3\u4e48\u7236\u5143\u7d20\u7684\u5bbd\u5ea6\u5c31\u662f100%\uff1b<\/p>\n<p>\u6240\u4ee5body\u9ed8\u8ba4\u5bbd\u5ea6\u662f\u5c4f\u5e55\u5bbd\u5ea6\uff08PC\u4e2d\u6307\u7684\u662f\u6d4f\u89c8\u5668\u5bbd\u5ea6\uff09\u5b50\u5b59\u5143\u7d20\u6309\u767e\u5206\u6bd4\u5b9a\u4f4d\uff08\u6216\u6307\u5b9a\u5c3a\u5bf8\uff09\u5373\u53ef\uff0c\u53ea\u9002\u5408\u5e03\u5c40\u7b80\u5355\u9875\u9762\uff0c\u590d\u6742\u9875\u9762\u5b9e\u73b0\u5f88\u56f0\u96be\u3002<\/p>\n<h2>Flex\u5f39\u6027\u5e03\u5c40<\/h2>\n<p>\u7565<\/p>\n<h2>table\u8868\u683c\u5e03\u5c40<\/h2>\n<p>\u7565<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528meta\u6807\u7b7e\uff1aviewport H5\u79fb\u52a8\u7aef\u9875\u9762\u81ea\u9002\u5e94\u666e\u904d\u4f7f\u7528\u7684\u65b9\u6cd5\uff0c\u7406\u8bba\u4e0a\u8bb2\u4f7f\u7528\u8fd9\u4e2a\u6807\u7b7e\u662f\u53ef\u4ee5\u9002\u5e94\u6240\u6709\u5c3a\u5bf8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[159],"class_list":["post-1028","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-h5"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1028"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1028\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}