I searched online and found that many interviews will ask questions about mobile adaptation methods. I have read some articles recently and would like to summarize them here. First, let’s talk about some technical solutions for mobile terminal adaptation that have appeared so far:
1. Media Queries @media screen and (max-width: 600px) { /*When the screen size is less than 600px, apply the following CSS style*/ /*your css code*/ } advantage
shortcoming
2.Flex layout Let’s use Tmall’s implementation method to illustrate: Its The height is fixed, the width is adaptive, and all elements use As the screen width changes, the page will also change accordingly. The effect is similar to the fluid layout of a PC page. When the width needs to be adjusted, just use the responsive layout (such as NetEase News), so that "adaptation" is achieved. 3. rem + viewport scaling This is also the solution used by Taobao. PS: rem Implementation principle Enlarge the page by If the DPR of iPhone 6 Plus is 3, the page will be enlarged 3 times, and 1px (CSS unit) is 3px (physical pixel) by default in Plus. In this way, the page width of the entire web page when displayed on the device will be equal to the device logical pixel size, that is, 4. rem implementation For example, the implementation of the "Meizu" mobile terminal, <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> Use the following code to control the !function (d) { var c = d.document; var a = c.documentElement; var b = d.devicePixelRatio; var f; function e() { var h = a.getBoundingClientRect().width, g; if (b === 1) { h = 720 } if(h>720) h = 720; //Set the limit value of the reference value g = h / 7.2; a.style.fontSize = g + "px" } if (b > 2) { b = 3 } else { if (b > 1) { b = 2 } else { b = 1 } } a.setAttribute("data-dpr", b); d.addEventListener("resize", function () { clearTimeout(f); f = setTimeout(e, 200) }, false); e() }(window); 1 pixel border HD 1. Taobao implementation method The Taobao implementation method mentioned above is to use div{ width: 1px; height: 100%; display: block; border-left: 1px solid #e5e5e5; -webkit-transform: scale(.5); transform: scaleX(.5); } shortcoming: Rounded corners cannot be achieved, and it is troublesome to achieve 4 borders, and it can only be achieved individually. If nested, it will have unwanted effects on the contained effects, so this solution is more often used independently with :after and before. Implementation method: Use CSS to process shadows to achieve a 0.5px effect. -webkit-box-shadow:0 1px 1px -1px rgba(0, 0, 0, 0.5); advantage: It can basically meet all scenarios, including rounded buttons, single lines, and multiple lines. shortcoming: Colors are difficult to handle, and black 2. Image Implementation There are two ways to achieve 1px using Single line: div{ height: 1px; background-image:-webkit-linear-gradient(top,transparent 50%,#000 50%); background-position: top left; background-repeat: no-repeat; background-size: 100% 1px; } Multiple lines: div{ background-image: -webkit-linear-gradient(top,transparent 50%,#000 50%), -webkit-linear-gradient(bottom, transparent 50%, #000 50%), -webkit-linear-gradient(left, transparent 50%, #000 50%), -webkit-linear-gradient(right, transparent 50%, #000 50%); background-size: 100% 1px,100% 1px,1px 100%,1px 100%; background-repeat: no-repeat; background-position: top left, bottom left, left top, right top; advantage: shortcoming: This is the end of this article about the mobile front-end adaptation solution (summary). For more relevant mobile front-end adaptation content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: v-for directive in vue completes list rendering
>>: Common parameters of IE web page pop-up windows can be set by yourself
Table of contents Lock Overview Lock classificati...
Monitoring method in Vue watch Notice Name: You s...
Table of contents 1. Select database USE 2. Displ...
The isnull() function cannot be used as a substit...
1. Type introduction 1.1 Domain-based virtual hos...
<br />Original text: http://jorux.com/archiv...
1Basic steps of echarts Four Steps 1 Find the DOM...
Table of contents Preface 1. Use $attrs and $list...
After reading some articles, I finally figured ou...
1. First, let’s have a general introduction to th...
npm installation tutorial: 1. Download the Node.j...
<div id="root"> <h2>Keep go...
This article uses examples to illustrate the func...
Effect: <!doctype html> <html> <he...
For containers, the simplest health check is the ...