Home Web Front-end HTML Tutorial CSS > 高清缩放原理分析_html/css_WEB-ITnose

CSS > 高清缩放原理分析_html/css_WEB-ITnose

Jun 21, 2016 am 08:52 AM

最近在研究 Retina 屏的适配问题,在具体方案讨论之前,陆续做了一些理解笔记,现归纳如下。具体方案的讨论将另作文章。

  1. 中的 viewport是布局视口

  2. initial-scale等的缩放是基于理想视口的

  3. 理想视口由设备各自提供,理想视口的宽度也是设备的独立像素

  4. 所谓“独立”是说这个设备独立像素和像素密度无关

  5. Retina屏增加了设备像素(物理像素),所以物理像素是有密度变化的

  6. dpr = 物理像素/设备独立像素 = 设备像素个数/设备理想视口宽度

  7. dpr 在 JavaScript 中可以通过 window.devicePixelRatio获取,在 CSS Media Query 中的名称是 device-pixel-ratio

  8. CSS像素和物理像素有区别,当1个CSS像素跨越更多物理像素时,就模糊了,反之则清晰,CSS像素被用在布局视口上

  9. 缩放可以调整CSS像素和物理像素之间的比例关系。高清屏的缩放方案就是:如将布局视口扩大为理想视口的2倍,即理想视口缩放比例为1/2,那么CSS像素将比以前跨越更少的物理像素,从而保证清晰度

    • 布局视口/理想视口 = CSS像素/设备独立像素 = 1/缩放比例

    • 物理像素/设备独立像素 = dpr

    • 页面清晰要求 —— CSS像素/物理像素 = 1

    • 故 —— 缩放比例 = 1/dpr

从以下的关系比中来认知:

  1. 布局视口(CSS像素) : 设备独立像素(理想视口) : 物理像素

  2. 设备独立像素可以被看做一个中间件:

    • 当 dpr=1 时,设 initial-scale=1.0,布局视口等于设备独立像素,设备独立像素等于物理像素,故布局视口等于物理像素,1CSS像素跨1物理像素

    • 当 dpr=2 时,设 initial-scale=1.0,布局视口等于设备独立像素,设备独立像素是物理像素的一半,故布局视口是物理像素的一半,1CSS像素跨4物理像素

    • 当 dpr=2 时,设 initial-scale=0.5,布局视口是设备独立像素的两倍,设备独立像素是物理像素的一半,故布局视口等于设备像素,1CSS像素跨1物理像素

  3. 再来研究高清屏,以下均设:设备独立像素是 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}

    • 所以,对于图来说,第一种情况下普通图片就会拉伸,从而模糊;第二种情况,就是使用高清图

  4. 为不同屏幕的元素设置不同的像素单位过于麻烦,开发者就需要考虑是否有跨屏幕的尺寸单位解决方案

    • rem:当普通屏时,设 :root{font-size: 10px},则 37.5rem 是 375px;高清屏时,设 :root{font-size: 20px},则 37.5rem 是 750px,因此,我们在 DIV 元素上只需要设置一个 37.5rem,在不同屏幕下更改根元素的字体大小,就可以兼容所有屏幕了

    • vw 和 wh:相对于布局视口大小计算尺寸,普通屏布局视口是 375px,高清屏是 750px,无论怎么变,vw/vh 单位的最后结果都会相应变化

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

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

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles