Mobile-page Adaptation Solutions

Source: Internet
Author: User

First, the fluid layout

The so-called fluid layout, that is, the width is defined as a percentage, the outermost container width is set to 100%, you can adapt to different screens, the sub-elements are proportional to set the percentage, the sum of the total percentage of the child element is 100%, but if there are child elements set the border, or padding, Then the overall width will be greater than 100%, then we can set the size of the box to calculate from the border, by setting: Box-sizing:border-box, at this time, the width of the box set is the actual width of the box, there is no problem.

Width solved, how is height set? The general element, the height can be fixed, so in the screen changes, we can see the width of the element has changed, the height is constant, but for the picture, if the height is different, the picture will be flattened, at this time we can set the width of the picture to 100%; its width is determined by the width of its parent, the height of the picture The image will be scaled up or down according to the width change, this is the characteristics of the picture, so that you can do the picture to fit.

Examples are as follows:

 *-sizing:border-box;    }. Wrap {Overflow:hidden;    }. banner {Overflow:hidden;    }. Banner img {width:  100 %;       }. L_con {width:  33.333333 %;       height:50px;     float  : Left;       }. C_con {width:  33.333333 %;       height:50px;     float  : Left;       }. R_con {width:  33.333333 %;       height:50px;     float  : Left; }

Second, the response style layout

Responsive layout, is the use of media queries, for different screens, corresponding to different styles, but mobile screen many kinds, if you want to correspond to so many different sets of styles, this is not realistic, so for mobile, can be divided into three screen width range, within the range, using the same set of styles, This defines three sets of styles can be, the width of the range can be referred to the resolution of the Apple Phone: 374px below the first interval, 375px to 413px for the second interval, 414px above is the third interval, according to this three interval defines three sets of styles, on the Apple phone can do a good adaptation, But for some other resolutions of the phone, there may be some less fitting details, but these three sets should basically be applied.

Examples are as follows:

/**/        ... ...          /*  *   /@media screen and (min-width:375px) {         ...   }         /* greater than or equal to 414px dimension style */ @media screen and   (min-width:414px) {        ...  }

Three, flexible box layout model

The elastic box layout model is a new CSS layout module, which has some characteristics of fluid layout and responsive layout, and it can realize the alignment, distribution and order of multiple elements with a small number of attributes, and it can quickly and efficiently implement the layout of the multi-terminal, which is referred to as Flexbox, The Flexbox layout module has three versions, some of the first two versions are not supported on the latest browsers, and a third version has been widely supported on the latest browsers.

The Flexbox layout module is a new property of CSS3, which is divided into container properties and entry properties, and containers and entries are concepts within this module, which are actually the parent and child elements. The parent element declares the Flexbox module by setting Display:flex, sets the arrangement of child elements through Flex-flow, sets the distribution of elements through justify-content, and so on. The child element sets the elongation or scale by the Flex attribute, sets its order in the container, and so on.

Examples are as follows:

. menu {   max-width:800px;   height:40px;    0 Auto;   Display:flex;   Justify-content:flex-start;   Align-items:center;}. Menu Li {   1;}

Iv. REM-based layouts

REM is a new unit of CSS3, relative to EM units, REM unit settings are more simple, it is relative to the root element of the font size, the other elements if using REM to set units, their corresponding datum is the same, so that in the mobile adaptation, in addition to HTML elements, other elements of the width, height , row height, background positioning and so on are set with REM, we set a width as a benchmark, such as 320px, and then according to this benchmark, proportional to adjust the size of the corresponding HTML elements on different screens, you can synchronously change all other elements of the size of the REM set size, This can be true proportional adaptation, unlike fluid layout, can only change the width, this method is direct, efficient, and is widely used in mobile-based layout.

The JavaScript that dynamically changes the size of the HTML tag text is as follows:

(function () {   = function () {       = document.documentelement;        640 640 : docelement.clientwidth;         -  the ' px ' ;   }   Calc ();   Window.addeventlistener ('resize', calc);}) ()

The CSS code is set up as follows:

. search{   Position:absolute;   Right:0. 725rem;   Top:0. 625rem;   Width:1. 35rem;   Height:1. 35rem;   Backgrond:url (.. /images/icons.png) left-97rem;    2  - . 5rem;   Background2. 5rem;}

In the actual development, we can choose the suitable fitting method according to the actual need.

Original source of this article: http://pcedu.pconline.com.cn/1024/10241144.html

Mobile-page adaptation solution

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.