Table of Contents
With the popularity of high-end mobile phones (Andriod, Iphone, Ipod, WinPhone, etc.), mobile Internet application development has attracted more and more attention. Using html5 to develop mobile applications is the best choice. However, each mobile phone has a different resolution and screen size. How can we make the application or page size we develop suitable for various high-end mobile phones? Learning the use of html5 viewport can help you do this...
viewport syntax introduction:
height
target-densitydpi
initial-scale
maximum-scale
user-scalable
Home Web Front-end H5 Tutorial Viewport screen adaptation in html5 development

Viewport screen adaptation in html5 development

Oct 13, 2017 am 10:18 AM
html5 ie viewport

With the popularity of high-end mobile phones (Andriod, Iphone, Ipod, WinPhone, etc.), mobile Internet application development has attracted more and more attention. Using html5 to develop mobile applications is the best choice. However, each mobile phone has a different resolution and screen size. How can we make the application or page size we develop suitable for various high-end mobile phones? Learning the use of html5 viewport can help you do this...

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]
       "
   />
Copy after login

width

To control the size of the viewport, you can specify a value or a special value. For example, device-width is the width of the device (the unit is CSS pixels when scaling to 100%).

height

corresponds to width and 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.

  • – Specify a specific dpi value as the target dpi. This value must be in the range of 70–400.


1	<!-- html document -->
2	<meta name="viewport" content="target-densitydpi=device-dpi" />
3	<meta name="viewport" content="target-densitydpi=high-dpi" />
4	<meta name="viewport" content="target-densitydpi=medium-dpi" />
5	<meta name="viewport" content="target-densitydpi=low-dpi" />
6	<meta name="viewport" content="target-densitydpi=200" />
Copy after login

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 is 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:

(Set the screen width to the device width and prohibit the user from manually adjusting the zoom)

(Set the screen density to high frequency, medium frequency, low frequency automatic scaling, prohibit the user from manually adjusting the scaling)

The above is the detailed content of Viewport screen adaptation in html5 development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles