


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.
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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In mobile development, we often encounter the problem of multi-finger touch. When users use multiple fingers to swipe or zoom the screen on a mobile device, how to accurately recognize and respond to these gestures is an important development challenge. In Vue development, we can take some measures to solve the problem of multi-finger touch on the mobile terminal. 1. Use the vue-touch plug-in vue-touch is a gesture plug-in for Vue, which can easily handle multi-finger touch events on the mobile side. We can install vue-to via npm

How to use mobile gesture operations in Vue projects With the popularity of mobile devices, more and more applications need to provide a more friendly interactive experience on the mobile terminal. Gesture operation is one of the common interaction methods on mobile devices, which allows users to complete various operations by touching the screen, such as sliding, zooming, etc. In the Vue project, we can implement mobile gesture operations through third-party libraries. The following will introduce how to use gesture operations in the Vue project and provide specific code examples. First, we need to introduce a special

CSSViewport: How to use vh, vw, vmin and vmax units to implement responsive design, specific code examples required In modern responsive web design, we usually want web pages to adapt to different screen sizes and devices to provide a good user experience. The CSSViewport unit (viewport unit) is one of the important tools to help us achieve this goal. In this article, we’ll cover how to use vh, vw, vmin, and vmax units to achieve responsive design.

How to use CSSViewport unit vh to create a web page layout adapted to mobile phone screens. The popularity and use of mobile phone devices is becoming more and more widespread, and more and more web pages need to be adapted to mobile phone screens. To solve this problem, CSS3 introduced a new unit - the Viewport unit, which includes vh (viewportheight). In this article, we will explore how to use vh units to create web page layouts that adapt to mobile screens, and provide specific code examples. one

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

The relationship between the number of Oracle instances and database performance Oracle database is one of the well-known relational database management systems in the industry and is widely used in enterprise-level data storage and management. In Oracle database, instance is a very important concept. Instance refers to the running environment of Oracle database in memory. Each instance has an independent memory structure and background process, which is used to process user requests and manage database operations. The number of instances has an important impact on the performance and stability of Oracle database.

With the popularity of mobile devices, using Vue for mobile development has become a common choice. However, we often face a problem during mobile development, which is double-clicking to zoom in. This article will focus on this problem and discuss how to solve the specific method of double-click amplification on the mobile terminal in Vue development. The double-click enlargement problem on mobile devices occurs mainly because the mobile device automatically enlarges the zoom ratio of the web page when double-clicking on the touch screen. For general web development, this kind of double-click to enlarge is usually beneficial because it can

Method of implementing mobile map positioning function using Python and Baidu Map API. With the development of mobile Internet, map positioning function has become more and more common in mobile applications. Python, as a popular programming language, can also implement mobile map positioning functions by using Baidu Map API. The following will introduce the steps to implement the map positioning function using Python and Baidu Map API, and provide corresponding code examples. Step 1: Apply for Baidu Map API Key Before starting, we first need to apply
