Implementation code for automatically adapting the width of the web page to the width of the mobile phone screen (viewport)

Implementation code for automatically adapting the width of the web page to the width of the mobile phone screen (viewport)

The general way of writing is as follows:

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "viewport"   content = "initial-scale=1.0" >   

More ways to write:

XML/HTML CodeCopy content to clipboard
  1. 1. < meta   name = "viewport"   content = "width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes"   />        


Adding the above sentence in the <head> of a web page will allow the width of the web page to automatically adapt to the width of the mobile phone screen.
in:

width=device-width: indicates that the width is the width of the device screen
initial-scale=1.0: indicates the initial scaling ratio
minimum-scale=0.5: indicates the minimum zoom ratio
maximum-scale=2.0: indicates the maximum zoom ratio
user-scalable=yes: Indicates whether the user can adjust the zoom ratio

If you want to open the web page, it will automatically display in its original proportions and not allow users to modify it, then:


Copy code
The code is as follows:

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />


After writing in this way, you can set the width of some header banners and other images to style="width:100%", and the entire page will look full screen on the device.

<<:  How to set the height of the autosize textarea in Element UI

>>:  Issues with Rancher deployment and importing K8S clusters

Recommend

mysql 5.7.18 winx64 password change

After MySQL 5.7.18 is successfully installed, sin...

CSS example code to hide the scroll bar and scroll the content

Preface When the HTML structure of a page contain...

How to add custom system services to CentOS7 systemd

systemd: The service systemctl script of CentOS 7...

A brief discussion on React Component life cycle functions

What are the lifecycle functions of React compone...

Detailed steps to build a file server in Windows Server 2012

The file server is one of the most commonly used ...

Installation of CUDA10.0 and problems in Ubuntu

The correspondence between tensorflow version and...

How to use Flex layout to achieve scrolling of fixed content area in the head

The fixed layout of the page header was previousl...

Detailed explanation of JavaScript to monitor route changes

Table of contents history pushState() Method push...

Three strategies for rewriting MySQL query statements

Table of contents Complex query and step-by-step ...

JavaScript implements the protocol example in which the user must check the box

In js, set the user to read a certain agreement b...