CSS pixels and solutions to different mobile screen adaptation issues

CSS pixels and solutions to different mobile screen adaptation issues

Pixel

Resolution

What we usually call monitor resolution actually refers to the resolution set by the desktop, not the physical resolution of the monitor. It’s just that LCD monitors have become mainstream now. Since the display principle of LCD is different from that of CRT, the display effect is best only when the desktop resolution is consistent with the physical resolution. Therefore, our desktop resolution is almost always consistent with the physical resolution of the monitor.

UI draft pixels

The pixels of the UI draft refer to the physical pixels. For example, 750px is the physical pixel of the UI design draft we received.

Front-end pixels

As long as the logical pixels of the two screens are the same, their display effects will be the same. That is, the px in the CSS world is the same, and the display effect on screens of the same physical size is the same

So what is the relationship between them when they are actually displayed on the screen?

As shown in the figure below, when we set the CSS pixel (width: 2px; height: 2px) of an element on a web page, it will eventually occupy four physical pixels on a display with dpr=1, and 16 physical pixels on a display with dpr=2. From this, we can conclude that the physical size of CSS pixels is consistent on different screens, but the number of physical pixels corresponding to one CSS pixel is different.

Rem adaptation solutions for different screens

<!-- m station mobile terminal adaptation js -->

  // Adapt to physical pixel width 750 1rem=100px   
  // clientWidth (actual logical pixel) / 375 (reference benchmark logical pixel) = fontSize (actual 1rem pixel value) / 100 (reference 1rem logical pixel value)
  ;(function(win, doc){
    function change(){
        doc.documentElement.style.fontSize=100*doc.documentElement.clientWidth/375+'px';
    }
    change();
    win.addEventListener('resize', change, false);
  })(window, document);
  // In this way, we can calculate the actual value of 1rem under different logical pixels. // In actual work, if the UI design draft width is 750px, then we need to divide the measured width by 200
  // When we open the console to check the distance between elements, it is half of the distance on the design draft. The physical pixel of the design draft is 2px, which corresponds to the logical pixel 1px.
  // Our company's current design drafts are all on Blue Lake. The width is standard 375. So we only need to divide the measured width by 100 to get the actual width in rem.

  // Attachment: Of course there are other adaptation schemes, but the rem principle is the same, unless the rem scheme is not adopted

Why do Apple phones need double or triple images?

Take 2x screen as an example

The original 2*2 pixel image is composed of 4*4 pixels on a 2x screen, so the pixels that need to be drawn will look for similar ones in the surrounding area, so there is a blur problem. In order to display high-definition images at work, Apple's double image is generally used.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  HTML thead tag definition and usage detailed introduction

>>:  Detailed graphic explanation of how to use svg in vue3+vite project

Recommend

MySQL 8.0.22 download, installation and configuration method graphic tutorial

Download and install MySQL 8.0.22 for your refere...

How to implement Echats chart large screen adaptation

Table of contents describe accomplish The project...

Summary of Docker Consul container service updates and issues found

Table of contents 1. Container service update and...

The difference and use of json.stringify() and json.parse()

1. Differences between JSON.stringify() and JSON....

js to realize the mouse following game

This article shares the specific code of js to im...

Detailed explanation of CSS3+JS perfect implementation of magnifying glass mode

About a year ago, I wrote an article: Analysis of...

Detailed explanation of the principle of js Proxy

Table of contents What is Proxy Mode? Introducing...

Summary of MySQL Architecture Knowledge Points

1. Databases and database instances In the study ...

Detailed explanation of some settings for Table adaptation and overflow

1. Two properties of table reset: ①border-collaps...

Pygame code to make a snake game

Table of contents Pygame functions used Creating ...

How to write DROP TABLE in different databases

How to write DROP TABLE in different databases 1....

mysql5.7.18.zip Installation-free version configuration tutorial (windows)

This is the installation tutorial of mysql5.7.18....

Navicat imports csv data into mysql

This article shares with you how to use Navicat t...