最近在研究 Retina 屏的适配问题,在具体方案讨论之前,陆续做了一些理解笔记,现归纳如下。具体方案的讨论将另作文章。
-
中的 viewport是布局视口
-
initial-scale等的缩放是基于理想视口的
-
理想视口由设备各自提供,理想视口的宽度也是设备的独立像素
-
所谓“独立”是说这个设备独立像素和像素密度无关
-
Retina屏增加了设备像素(物理像素),所以物理像素是有密度变化的
-
dpr = 物理像素/设备独立像素 = 设备像素个数/设备理想视口宽度
-
dpr 在 JavaScript 中可以通过 window.devicePixelRatio获取,在 CSS Media Query 中的名称是 device-pixel-ratio
-
CSS像素和物理像素有区别,当1个CSS像素跨越更多物理像素时,就模糊了,反之则清晰,CSS像素被用在布局视口上
-
缩放可以调整CSS像素和物理像素之间的比例关系。高清屏的缩放方案就是:如将布局视口扩大为理想视口的2倍,即理想视口缩放比例为1/2,那么CSS像素将比以前跨越更少的物理像素,从而保证清晰度
-
布局视口/理想视口 = CSS像素/设备独立像素 = 1/缩放比例
-
物理像素/设备独立像素 = dpr
-
页面清晰要求 —— CSS像素/物理像素 = 1
-
故 —— 缩放比例 = 1/dpr
-
从以下的关系比中来认知:
-
布局视口(CSS像素) : 设备独立像素(理想视口) : 物理像素
-
设备独立像素可以被看做一个中间件:
-
当 dpr=1 时,设 initial-scale=1.0,布局视口等于设备独立像素,设备独立像素等于物理像素,故布局视口等于物理像素,1CSS像素跨1物理像素
-
当 dpr=2 时,设 initial-scale=1.0,布局视口等于设备独立像素,设备独立像素是物理像素的一半,故布局视口是物理像素的一半,1CSS像素跨4物理像素
-
当 dpr=2 时,设 initial-scale=0.5,布局视口是设备独立像素的两倍,设备独立像素是物理像素的一半,故布局视口等于设备像素,1CSS像素跨1物理像素
-
-
再来研究高清屏,以下均设:设备独立像素是 375px,dpr=2,物理像素则是 750px,元素DIV div{width: 375px}:
-
initial-scale=1.0 时,1CSS像素跨越4物理像素,故 DIV 是满屏的
-
initial-scale=0.5 时,1CSS像素跨越1物理像素,故 DIV 只占屏幕的一半,要想同样保持全屏,就需要把 DIV 改为 div{width: 750px}
-
所以,对于图来说,第一种情况下普通图片就会拉伸,从而模糊;第二种情况,就是使用高清图
-
-
为不同屏幕的元素设置不同的像素单位过于麻烦,开发者就需要考虑是否有跨屏幕的尺寸单位解决方案
-
rem:当普通屏时,设 :root{font-size: 10px},则 37.5rem 是 375px;高清屏时,设 :root{font-size: 20px},则 37.5rem 是 750px,因此,我们在 DIV 元素上只需要设置一个 37.5rem,在不同屏幕下更改根元素的字体大小,就可以兼容所有屏幕了
-
vw 和 wh:相对于布局视口大小计算尺寸,普通屏布局视口是 375px,高清屏是 750px,无论怎么变,vw/vh 单位的最后结果都会相应变化
-

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.