


This article shares the viewport attribute to solve the problem of the font being reset when switching from vertical screen to horizontal screen on the mobile terminal. When I first started working on it, I never tested the page on my mobile phone. As a result, after I wrote several pages, I found that the page was extremely small and almost invisible.
The reason is that each mobile device has its own default viewport width.
Viewport: There are two viewports in mobile browsers: visible viewport (device screen size) and browser viewport (webpage width).
Take the iPhone 4s as an example. Its screen is 320*480, but it can display content with a width of 980 pixels (the default for iPhone is 980), so when you put a webpage on the mobile side and display it, it is equivalent to Shrunk by 980/320. The purpose of doing this on mobile phones is to display more things, but the result is that the pages made on the PC are as small as ants on the mobile terminal!
The mobile version has a meta tag: viewport. You can use this tag to set the browser viewport width to be the same as the visible viewport width.
<meta name="viewport" content="width=device-width">
For some old mobile device browsers that do not support viewport (well, maybe, such as BlackBerry), you can use the following code
<meta name="HandheldFriendly" content="true">
But I think not many people use it now For this, usually just write the first line.
Speaking of viewport, he actually has some other attributes:
initial-scale: initial scaling ratio
maximum-scale: allows scaling Maximum scale
minimum-scale: The minimum scale allowed for scaling
user-scalable: Whether to allow manual scaling
What are these properties used for?
When the mobile device switches from portrait to landscape, the font will be reset and become very large. How to solve it?
You only need to set it like this
<meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1>
The default zoom ratio of the page is 1, and the allowed zoom is also 1-1, which is equivalent to disabling zoom. The browser will only define it according to the style. Font size rendering.
You may see this way of writing.
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" >
But in fact, when you use the user-scalable=no attribute, minimum-scale=1, maximum-scale=1 have been ignored, because you have disabled scaling.
I found some more specific explanations elsewhere:
1) Does user-scalable=no guarantee that the page cannot be scaled? NO, some browsers don't like this. Another trick is minimum-scale=1.0, maximum-scale=1.0. Just set the maximum and minimum scaling ratio to 1.0.
2), initial-scale=1.0 Is the initial scaling controlled by user-scalable? Not necessarily. Some browsers will interpret user-scalable as manual scaling by the user. If user-scalable=no, initial-scale will not take effect.
3). The mobile page can be moved by touch, but if there is a need to prohibit this operation, the page width is equal to the screen width and the page fits the screen exactly to ensure that the page cannot be moved.
4). If the page is reduced to fit the screen width, a problem will arise. When the text box is activated (gets focus), the page will be enlarged to its original size.
Therefore, for the sake of safety, it is recommended to use the second way of writing.
Of course, the disadvantage of this is that users are prohibited from zooming. There is a compromise method in "Web Development Practice". If you are interested, you can take a look. I will not describe it here.
A little digression:
There is a property in CSS3: -webkit-text-size-adjust.
This attribute also prohibits font scaling. The advantage of this attribute is that the range can be customized and set according to project requirements.
It should be noted that the function of this attribute is to disable the text size adjustment function of the Webkit kernel browser rather than to control the page zoom. The minimum font limit of the Chinese version of Chrome browser is 12px.
However, due to the abuse of this attribute, desktop browsers no longer supported it a few years ago, so I have never actually used it. I only saw it in other materials.
【Related Recommendations】
1. Special Recommendation:"php Programmer Toolbox" V0.1 version Download
2. Example code about viewport compatibility issues
3. viewport special topic: in-depth understanding of responsive Web design in css-viewport
4. Introduction to the parameters of Viewport in HTML5 and how to use it
The above is the detailed content of Share the viewport attribute to solve the problem of the font being reset when switching from vertical screen to horizontal screen on the mobile terminal.. For more information, please follow other related articles on the PHP Chinese website!

在移动端开发中,我们经常会遇到多手指触控的问题。当用户在移动设备上使用多个手指滑动或缩放屏幕时,如何准确地识别和响应这些手势是一个重要的开发难题。在Vue开发中,我们可以采取一些措施来解决移动端多手指触控问题。一、使用vue-touch插件vue-touch是一个用于Vue的手势插件,它可以方便地处理移动端的多手指触控事件。我们可以通过npm安装vue-to

CSSViewport:如何使用vh、vw、vmin和vmax单位来实现响应式设计,需要具体代码示例在现代响应式网页设计中,我们通常希望网页能够适应不同屏幕尺寸和设备,以提供良好的用户体验。而CSSViewport单位(视口单位)就是帮助我们实现这一目标的重要工具之一。在本文中,我们将介绍如何使用vh、vw、vmin和vmax单位来实现响应式设

如何使用CSSViewport单位vh来创建适配手机屏幕的网页布局手机设备的普及和使用越来越广泛,越来越多的网页需要进行手机屏幕的适配。为了解决这个问题,CSS3引入了一个新的单位——Viewport单位,其中包括vh(viewportheight)。在这篇文章中,我们将探讨如何使用vh单位来创建适配手机屏幕的网页布局,并提供具体的代码示例。一

随着移动端设备的普及,使用Vue进行移动端开发已经成为了常见的选择。然而,我们在移动端开发过程中经常会面临一个问题,就是双击放大。本文将针对这一问题,探讨在Vue开发中如何解决移动端双击放大的具体方法。移动端双击放大问题的出现,主要是因为移动设备在触摸屏上进行双击操作时,会自动放大网页的缩放比例。对于一般的网页开发来说,这种双击放大通常是有好处的,因为它可以

使用CSSViewport单位vh和vmin创建媒体查询的技巧随着移动设备的普及,响应式设计已成为现代网页设计的必备技术。为了适应不同大小的屏幕,开发人员需要通过媒体查询来调整布局和样式。而在媒体查询中,最常用的单位是像素(px)。然而,CSS3引入了一种新的视窗单位,即vh和vmin,它们能够更好地适应不同设备尺寸。本文将介绍如何使用vh和v

Vue开发中如何解决移动端手势缩放页面卡顿问题近年来,移动端应用的普及使得手势操作成为用户交互的重要方式。在Vue开发中,实现移动端手势缩放功能往往会遇到页面卡顿的问题。本文将探讨如何解决这一问题,并提供一些优化策略。了解手势缩放原理在解决问题之前,我们首先需要了解手势缩放的原理。手势缩放通过监听触摸事件来实现,当用户用两个手指滑动屏幕时,页面会按照手指的滑

Vue开发中如何解决移动端点击穿透问题移动端上经常会遇到点击穿透的问题,即用户在快速点击元素时,由于点击事件的执行时间较长,下一个元素会被穿透点击。这在开发中会造成一系列的问题,例如多次触发事件、页面跳转错误等。针对这个问题,Vue提供了几种解决方案。一、使用FastClick库FastClick是一个能够消除click事件在移动端300ms的延迟库。安装和

随着移动互联网的快速发展,越来越多的网站和应用程序开始采用Vue.js进行移动端开发。然而,在移动端开发过程中,经常会遇到图片旋转的问题。图片旋转是指当用户在移动设备上拍摄照片时,由于设备方向的变化,导致照片在页面上显示的角度与实际拍摄的角度不一致。解决图片旋转问题,首先需要了解图片旋转的原因。当用户在移动设备上拍摄照片时,设备会自动为照片添加一些元数据,其


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
