What are the layout solutions for mobile terminals in HTML?
Recently, I have studied the wap homepage style layout of Taobao, Tmall and NetEase Lottery 163. Today I will summarize some mobile layout plans for you and analyze the pros and cons of the technologies used.
Note: The code runs using the file protocol. Reference to local files is not supported in Chrome, and a cross-domain error will be prompted. You can open it with Firefox or Safari
wty2368
Mobile Layout Plan Research
Study the WAP homepage style layout of Taobao, Tmall and NetEase Lottery 163, and summarize the mobile layout plan
Note: The code runs under the file protocol and does not support references in Chrome Local files will prompt a cross-domain error. You can use Firefox or Safari to open them.
Download the ppt made at that time: Research on mobile layout plan in December 2015
1. Physical pixel
A physical pixel is the smallest physical display unit on the display (mobile phone screen)
2. Device-independent pixel (density) -independent pixel)
Device-independent pixel (also called density-independent pixel) can be thought of as a point in the computer coordinate system. This point represents a virtual pixel that can be used by the program (for example: CSS pixel)
3. Bitmap pixel
A bitmap pixel is the smallest data unit of a raster image (such as png, jpg, gif, etc.). Each bitmap pixel contains some of its own display information (such as display position, color value, transparency, etc.)
4. Device pixel ratio (referred to as dpr)
Device pixel ratio = Physical pixels/device independent pixels (in a certain direction, x direction or y direction)
5. scale
Scale ratio:
scale = 1/dpr
6. Perfect viewport
<meta name="viewport" content="initial-scale=1,width=device-width,user-scalable=0,maximum-scale=1" />
2. NetEase Lottery Design Plan
NetEase Lottery
Use scale = 1.0 to write the viewport
Use Media Query to determine the html The font-size value of the root element, that is, the rem value
rem + percentage layout
The css code of the media query is as follows:
//网易彩票的响应式布局是采用媒体查询来改变rem值实现的 //媒体查询css#media-query{ @media screen and (min-width: 240px) { html,body,button,input,select,textarea { font-size:9px!important; } } @media screen and (min-width: 320px) { html,body,button,input,select,textarea { font-size:12px!important; } } @media screen and (min-width: 374px) { html,body,button,input,select,textarea { font-size:14px!important; } } @media screen and (min-width: 400px) { html,body,button,input,select,textarea { font-size:15px!important; } } // 省略 }
3. Day Cat design plan
Tmall homepage
Use scale = 1.0 to hard-code the viewport
Do not use rem, and the body’s font-size=14px is hard-coded
px + flexbox layout
4. Problems encountered
1. 1px line blur problem under high-definition screen (dpr>1)
In most cases, designers produce When producing manuscripts of various sizes, I first draw a large size (usually 2x) manuscript, then reduce the size, and finally export it. This will cause problems: if the designer draws a 1px line (for example, border: 1px) in the 2x manuscript, if we want to present it in scale=1.0, it will become 0.5px, which is very large Some mobile phones cannot draw 0.5px.
Theoretically, 1 bitmap pixel corresponds to 1 physical pixel, so that the picture can be displayed perfectly and clearly. There is no problem on a normal screen, but on a retina screen (dpr=2) there will be not enough pixels in the bitmap, resulting in a blurry picture.
2. The problem of blurring high-definition pictures under high-definition screens (dpr>1)
For retina screens with dpr=2, 1 bitmap pixel corresponds to 4 physical pixels. Since a single Bitmap pixels cannot be further divided, so the nearest color can only be taken, resulting in a blurred picture (note the above color values). Therefore, for the problem of high-definition pictures, a better solution is to use twice the picture. For example: 200×300(css pixel)img tag, you need to provide a 400×600 image.
For the retina screen with dpr=2, 1 bitmap pixel corresponds to 4 physical pixels. Since a single bitmap pixel cannot be further divided, the color can only be taken from the nearest location, resulting in blurred pictures (note the above several color values). Therefore, for the problem of high-definition pictures, a better solution is to use twice the picture. For example: 200×300 (css pixel) img tag, you need to provide a 400×600 image.
5. The ultimate solution-->Taobao design plan
Taobao homepage
Get the dpr parameters of the mobile phone through js processing, and then dynamically generate the viewpoint
Get the physical pixel width of the mobile phone and divide it into 10 parts. The width of each part is the size of rem.
According to the size of the design draft (px), it will be processed in three situations, using px + rem layout
The relevant scripts are as follows:
$(document).ready(function(){ var dpr, rem, scale; var docEl = document.documentElement; var fontEl = document.createElement('style'); var metaEl = document.querySelector('meta[name="viewport"]'); var view1 = document.querySelector('#view-1'); if(window.screen.width < 540){ dpr = window.devicePixelRatio || 1; scale = 1 / dpr; rem = docEl.clientWidth * dpr / 10; }else{ dpr = 1; scale =1; rem = 54; }//貌似最新的淘宝网站又去掉了,只是限制了主体内容的宽度 // 设置viewport,进行缩放,达到高清效果 metaEl.setAttribute('content', 'width=' + dpr * docEl.clientWidth + ',initial-scale=' + scale + ',maximum-scale=' + scale + ', minimum-scale=' + scale + ',user-scalable=no'); // 设置整体div的宽高 view1.setAttribute('style', 'width:'+ docEl.clientWidth+'px; height:'+ docEl.clientHeight+'px'); // 设置data-dpr属性,留作的css hack之用 docEl.setAttribute('data-dpr', dpr); // 动态写入样式 docEl.firstElementChild.appendChild(fontEl); fontEl.innerHTML = 'html{font-size:' + rem + 'px!important;}'; $('body').attr('style', 'font-size:' + dpr * 12 +'px'); // 给js调用的,某一dpr下rem和px之间的转换函数 window.rem2px = function(v) { v = parseFloat(v); return v * rem; }; window.px2rem = function(v) { v = parseFloat(v); return v / rem; }; window.dpr = dpr; window.rem = rem;})
6. Summary of design plan
From the above analysis, it is not difficult to see that:
NetEase Lottery’s solution is quick to use, has high development efficiency, and has good compatibility, but it is not flexible and sophisticated enough;
Tmall’s solution The design idea is relatively simple, flexbox is very flexible, but the compatibility of flexbox needs to be handled carefully and is not precise enough;
Taobao's solution solves almost all the problems encountered on the mobile side, and it is a perfect solution, but Development efficiency is low and cost is relatively high.
I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
What are the techniques for using scroll bars in HTML
html jump to other pages in two seconds
How to set up the hidden other in a tag The property only displays pictures
The above is the detailed content of What are the layout solutions for mobile terminals in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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

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.

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

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

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

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

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