The Internet is developing faster and faster, and various technologies are emerging one after another. The display sizes and resolutions of various devices are different. This is also a problem that our front-end personnel are currently struggling with: how to develop once and be friendly on different interfaces. Show it!
Fortunately Viewport appears in HTML5! The emergence of Viewport allows the applications or pages we develop to be displayed uniformly and friendly on devices of different sizes!
viewport syntax introduction:
<!– html document –> <meta name=”viewport” content=” height = [pixel_value | device-height] , width = [pixel_value | device-width ] , initial-scale = float_value , minimum-scale = float_value , maximum-scale = float_value , user-scalable = [yes | no] , target-densitydpi = [dpi_value | device-dpi | high-dpi | medium-dpi | low-dpi] ” />
Parameter explanation:
width - controls the size of the viewport. You can specify a value or a special value. For example, device-width is the width of the device (unit is CSS pixels when scaling to 100%).
height - corresponds to width, specifies the height
target-densitydpi - a screen pixel density is determined by the screen resolution, usually defined as the number of dots per inch (dpi) . Android Supports three screen pixel densities: low pixel density, medium pixel density, and high pixel density. A low pixel density screen has fewer pixels per inch, while a high pixel density screen has more pixels per inch. Android Browser and WebView default screens are medium pixel density.
The following is the value range of the target-densitydpi attribute
device-dpi: Use the original dpi of the device as the target dp. Default scaling does not occur.
high-dpi: Use hdpi as the target dpi. Medium pixel density and low pixel density devices scale down accordingly.
medium-dpi: Use mdpi as the target dpi. Devices with high pixel density scale up accordingly, and devices with pixel density scale down accordingly. This is the default target density.
low-dpi: Use mdpi as the target dpi. Medium pixel density and high pixel density devices scale up accordingly.
<!– html document –> <meta name=”viewport” content=”target-densitydpi=device-dpi” /> <meta name=”viewport” content=”target-densitydpi=high-dpi” /> <meta name=”viewport” content=”target-densitydpi=medium-dpi” /> <meta name=”viewport” content=”target-densitydpi=low-dpi” /> <meta name=”viewport” content=”target-densitydpi=200″ />
To prevent Android Browser and WebView from scaling your page based on the pixel density of different screens, you can set the viewport's target-densitydpi to device-dpi. When you do this, the page will not scale. Instead, the page is displayed based on the pixel density of the current screen. In this case, you also need to define the viewport's width to match the device's width so that your page can fit on the screen.
initial-scale——Initial scaling. That is, the initial zoom level of the page. This is a floating point value that is a multiplier of the page size. For example, if you set the initial scaling to "1.0", then the web page will be displayed at 1:1 of the target density resolution when displayed. If you set it to "2.0", then the page will be enlarged to 2 times.
maximum-scale——Maximum scaling. That is, the maximum degree of scaling allowed. This is also a floating point value indicating the maximum multiplier of the page size compared to the screen size. For example, if you set this value to "2.0", then the page can be enlarged up to 2 times compared to the target size.
user-scalable – User-adjustable scaling. That is, whether the user can change the zoom level of the page. If set to yes, the user is allowed to change it, otherwise it is no. The default value is yes. If you set it to no, both minimum-scale and maximum-scale will be ignored, since scaling is not possible at all.
All scaling values must be within the range of 0.01–10.
Example: 1. Set the screen width to the device width, prohibit the user from manually adjusting the zoom
<meta name=”viewport” content=”width=device-width,user-scalable=no” />
Example: 2. Set the screen density to high frequency, medium frequency, low frequency automatic scaling, prohibit the user from manual adjustment Zoom
<meta name=”viewport” content=”width=device-width,target-densitydpi=high-dpi,initial-scale=1.0
【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
The above is the detailed content of Introduction to the parameters of Viewport in HTML5 and how to use it. For more information, please follow other related articles on the PHP Chinese website!

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.

H5 (HTML5) will improve web content and design through new elements and APIs. 1) H5 enhances semantic tagging and multimedia support. 2) It introduces Canvas and SVG, enriching web design. 3) H5 works by extending HTML functionality through new tags and APIs. 4) Basic usage includes creating graphics using it, and advanced usage involves WebStorageAPI. 5) Developers need to pay attention to browser compatibility and performance optimization.

H5 brings a number of new functions and capabilities, greatly improving the interactivity and development efficiency of web pages. 1. Semantic tags such as enhance SEO. 2. Multimedia support simplifies audio and video playback through and tags. 3. Canvas drawing provides dynamic graphics drawing tools. 4. Local storage simplifies data storage through localStorage and sessionStorage. 5. The geolocation API facilitates the development of location-based services.

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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