"Layman's It" mobile web responsive REM and viewport

Source: Internet
Author: User

In the writing of mobile phone pages, the problem of pixels will be very confused, beginners many times because of a small point of the problem can not be solved, or can not understand thoroughly give up learning.

I have been learning to write mobile Web page also puzzled for a long time, there have been the following problems:

The image footage was designed in 640px*330px pixels, placed in IMG, and IMG was set to fill full screen style:

. img{    width:100%;    Height:16.5rem;]

PS: I set the HTML

html{    font-size:20px;    }

So according to the REM algorithm, the height of the IMG should be 330px/20px=16.5rem (how does REM work?). The next article will be used in our layman's vernacular to illustrate)

At this time in Chrome Google browser debugging effect, found that the width of the image into 980px, and then all kinds of REM calculation is not right, really do not want to understand, why their own picture is 640px wide, how to the browser is magnified to 980, and then read the article of the Great God on the Internet, found the browser on the mobile device will set its default viewport to 980px or 1024px .

So this time we need to add the following code to the

<meta name= "viewport" content= "Width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" >

The META tag's purpose is to make the current viewport width equal to the width of the device, while not allowing the user to scale manually. May not allow users to scale different sites have different requirements, but let viewport width equal to the width of the device, this should be the effect that everyone wants, if you do not set it, then will use that than the screen width of the default viewport, that is, the horizontal scroll bar appears.

What exactly is this meta tag named viewport, and what does it do?

The meta viewport tag was first introduced by Apple in its Safari browser to address the viewport problem of mobile devices. Later on, Android and the big browser vendors followed suit and introduced support for Meta viewport, which proved to be very useful.

In Apple's specification, Meta viewport has 6 attributes, as follows:

width set layout viewport   width as a positive integer, or string "Width-device"
Set the initial zoom value of the page, as a number, with decimal
allows the user's minimum zoom value, which is a number, can be taken with decimals
maximum-scale Allows the user's maximum zoom value, which is a number that can be taken with decimals
settings layout viewport   Height, this property is not important to us, very few use
Whether the user is allowed to scale, the value is "no" or "yes", no is not allowed, yes means allow

These properties can be used at the same time, or they can be used alone or mixed, and multiple properties are separated by commas when used simultaneously.

"Layman's It" mobile web responsive REM and viewport

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.