The concept of things do not say, directly look at the scheme and the relevant library, who let us is the master tune library. I don’t know how to implement, but I’m good with libraries. Manual dog head 😃
1. media
Css3 Media query: Compile CSS styles suitable for devices with different resolutions through media query. Usually need to UI out of different sizes of the design draft, and then corresponding development. This scheme is not very common and is used in grid systems.
@media screen and (max-width: 320px) {... CSS styles for iphone4@media screen and (max-width: 375px) {... Adapter iphone6 /7/8CSS style}@media screen and (max-width: 414px) {... Adapter iphone6 /7/8Plus CSS style}Copy the code
Disadvantages:
- The workload is large, and the later maintenance is also large.
pc
h5
Can achieve the effect.
Advantages:
- I just need to modify it
css
, can achieve the effect. - It will automatically adjust according to the screen
Commonly used library:
Bootsrtap, and rasterization systems for various UI frameworks. Here’s an example of rasterization for ANTD. And element, of course.
2. rem
Rem is the font-size relative to the browser HTML elements. Adapt by changing the FONT size of the HTML. They are often paired with viewPorts to dynamically set the viewport.
Commonly used library:
Hotcss Flexible. Js, PostCSs-PxtoREM is mainly used in engineering projects, you write PX into REM, Px2REM
Advantages:
- Good adaptation, browser support.
Disadvantages:
- You have to do calculations, and now a lot of them can be directly exported
rem
Design draft for the unit. - If the setting of the value of the decimal point is not easy to understand, and there is a certain error, not intuitive.
4. vw/vh
The percentage /
The difference with REM is that the units are vw over vh, which is relative to viewport to determine the size. The percentage is compared to VW/VH and REM, and is based on the parent element, not the root element. In actual use, you need to calculate the percentage of the layout.
Commonly used library:
Postcss-px-to-viewport is the same as postCSs-pxtorem, which converts units to VW /vh.
Advantages:
- No human passage is required
js
Operation to change the size of the root element, directly usingcss
New unit, automatic.
Disadvantages:
- Direct conversion of the percentage may appear decimal, calculation is inconvenient and error. It’s not intuitive.
- Compatibility is not there
rem
Ok.
5. css3 transform
/ zoom
This should be a new solution for now. Css3’s Transform is used to scale the desired container. Note that the Zoom attribute is not supported on Firfox. This scheme is commonly used on large PC screens.
Common library: need to achieve their own implementation, implementation is relatively simple, obtain the width of the visible area of the web page height, go in to calculate the scaling ratio, and finally add to the need to scale the container
Advantages:
- Completely controlled
Disadvantages:
- Browser support required
css3
- Used in the
fixed
There is a problem with the positioned element