The viewport of mobile web development

Source: Internet
Author: User

Problem:

wrote a responsive page on Codepen, no problem when debugging. The results are placed on the website, and the layout is the same on the computer after it is opened on the phone.

Read the information and know that the responsive layout should have such a sentence: <meta name= "viewport" content= "width=device-width,initial-scale=1.0, maximum-scale=1.0, User-scalable=0 ">

What's going on here? Why is it that the width=device-width can be correctly displayed as shown in Figure II?

Viewport birth

The matter begins before the viewport appears.

When mobile devices are not popular, web design does not take into account the feelings of the mobile phone, if you use a mobile device (screen width of 320px) open a fixed width (width:980px) page, there will be scroll bar, to swipe to read the entire page:

It's not the worst. Worst of all, if it's a streaming layout. That is, the width of a box is a percentage, say 20%, then the actual width of the box will be 320px*20%=64px when opened on a phone with a screen width of 320px. And it's inside the PX unit of the text, is still so large. This will be the case where only a few words are allowed in a row, and the reading experience is very poor.

To solve this problem, Apple puts forward the concept of viewport, which is equivalent to a separate viewport on the device screen that shows the content of the Web page, leaving the CSS completely disconnected from the device's width. In other words, the percentage in CSS is determined by its width, not by the physical width of the device screen. Apple gives it a default width of 980px.

This is why my responsive Web page is on the phone and the layout is the same on the computer, because I open it in viewport, and the width of viewport is 980px, and it doesn't meet breakpoint, so it doesn't change the layout.

With the popularity of mobile, the problem is becoming more and more difficult, those specifically for mobile phone design Web page (width 320px), on the phone after the opening is like this:

So you need to provide some properties to set the width or height of the viewport.

<meda name= "viewport" width= "Device-width" >

In this way, the page will be displayed correctly:

Reference:

    • What is viewport, why need viewport
    • A pixel is not a pixel was not a pixel

Viewport of mobile Web development

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.