日记首页
|
列表
|
添加日记
|
管理登陆
标题:手机访问,让页面放大一倍
<font face="Arial" style="font-size: 10.5pt;"><span style="font-size: 10.5pt;">手机访问,让页面放大一倍,不同类型的代码:</span></font><div style="font-size: 10.5pt; font-family: Arial;"><b style="">1.html:</b></div><div style=""><font size="2"><span style="white-space: pre-wrap;"> <style> </span><br><span style="white-space: pre-wrap;"> /* 默认样式 */ </span><br><span style="white-space: pre-wrap;"> body { </span><br><span style="white-space: pre-wrap;"> font-size: 16px; </span><br><span style="white-space: pre-wrap;"> } </span><br><span style="white-space: pre-wrap;"> </span><br><span style="white-space: pre-wrap;"> /* 当屏幕宽度小于600px时应用的样式 */ </span><br><span style="white-space: pre-wrap;"> @media screen and (max-width: 600px) { </span><br><span style="white-space: pre-wrap;"> body { </span><br><span style="white-space: pre-wrap;"> font-size: 20px; /* 放大字体 */ </span><br><span style="white-space: pre-wrap;"> } </span><br><span style="white-space: pre-wrap;"> /* 其他针对小屏幕的样式调整 */ </span><br><span style="white-space: pre-wrap;"> } </span><br><span style="white-space: pre-wrap;"> </style> </span></font><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Ubuntu, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei UI, Microsoft YaHei, Source Han Sans CN, sans-serif, Apple Color Emoji, Segoe UI Emoji" style="font-size: 10.5pt;"><font color="rgba(0, 0, 0, 0.850980392156863)"><span style="font-size: 10.5pt; white-space: pre;"> </span></font></font><br></div><div style="font-size: 10.5pt;"><hr></div><div style="font-size: 10.5pt;"><b>2.asp:</b></div><div style="font-size: 10.5pt;"><div><font size="2"><% </font></div><div><font size="2">' 判断用户代理是否包含手机关键字 </font></div><div><font size="2">Dim userAgent </font></div><div><font size="2">userAgent = Request.ServerVariables("HTTP_USER_AGENT") </font></div><div><font size="2"> </font></div><div><font size="2">If InStr(userAgent, "Mobile") > 0 Or InStr(userAgent, "Android") > 0 Or InStr(userAgent, "iPhone") > 0 Or InStr(userAgent, "iPad") > 0 Then </font></div><div><font size="2"> ' 手机访问,设置视口宽度为设备宽度,并禁止缩放 </font></div><div><font size="2"> Response.Write("<meta name=""viewport"" content=""width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"">") </font></div><div><font size="2"> ' 放大网页字体一倍 </font></div><div><font size="2"> Response.Write("<style type=""text/css"">body { font-size: 2em; }</style>") </font></div><div><font size="2">End If </font></div><div><font size="2">%></font></div><div><font size="2"><br></font></div><div><hr></div><div><b>3.php:</b></div><div><font size="2"><div><?php</div><div>// 判断用户访问是否包含手机端</div><div>$userAgent = $_SERVER['HTTP_USER_AGENT'];</div><div><br></div><div>if (strpos($userAgent, 'Mobile') !== false || strpos($userAgent, 'Android') !== false || strpos($userAgent, 'iPhone') !== false || strpos($userAgent, 'iPad') !== false) {</div><div> // 手机访问,设置视口宽度为设备宽度,并禁止缩放</div><div> echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">';</div><div> // 放大网页字体一倍</div><div> echo '<style type="text/css">body { font-size: 2em; }</style>';</div><div>}</div><div>?></div><div><!-- 判断终端,手机端会放大字体一倍 ,否则直接输出电脑端页面 --></div></font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div></div>