2018-10-10 18:03:03 -04:00
---
id: 587d78b1367417b2b2512b0a
challengeType: 0
2020-02-11 21:30:05 +08:00
videoUrl: 'https://scrimba.com/c/cPp7VfD'
forumTopicId: 1
2020-10-01 17:54:21 +02:00
title: 针对高分辨率屏幕应使用视网膜图片
2018-10-10 18:03:03 -04:00
---
## Description
2020-02-11 21:30:05 +08:00
< section id = 'description' >
随着联网设备的增加, 设备的尺寸和规格有所不同, 它们使用的显示器在内部和外部可能也不同。像素密度( PPI 或 DPI) 就是设备之间的其中一个不同点。最著名的显示器就是最新的 Apple MacBook Pro 笔记本电脑和最近的 iMac 电脑上的“视网膜显示器”。由于“视网膜”和“非视网膜”显示器之间的像素密度不同,某些未考虑高分辨率显示器的图像在高分辨率显示器上渲染时可能看起来“像素化”。
使图像在高分辨率显示器(例如 MacBook Pro 的“视网膜显示器”)上正常显示的最简单方法是将其 width 和 height 值设置为原始文件的一半,如下所示:
```html
< style >
img { height: 250px; width: 250px; }
< / style >
< img src = "coolPic500x500" alt = "A most excellent picture" >
```
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2020-02-11 21:30:05 +08:00
< section id = 'instructions' >
设置 < code > img< / code > 标签的 < code > width< / code > 和 < code > height< / code > 为它们原始宽高的一半。在这个例子中,原始 < code > height< / code > 和原始 < code > width< / code > 的值都为 200px。
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2020-02-11 21:30:05 +08:00
- text: '< code > img</ code > 标签的 < code > width</ code > 值应为 100px。'
2020-02-18 01:40:55 +09:00
testString: assert($('img').css('width') == '100px');
2020-02-11 21:30:05 +08:00
- text: '< code > img</ code > 标签的 < code > height</ code > 值应为 100px。'
2020-02-18 01:40:55 +09:00
testString: assert($('img').css('height') == '100px');
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'html-seed' >
```html
< style >
2020-02-11 21:30:05 +08:00
2018-10-10 18:03:03 -04:00
< / style >
< img src = "https://s3.amazonaws.com/freecodecamp/FCCStickers-CamperBot200x200.jpg" alt = "freeCodeCamp sticker that says 'Because CamperBot Cares'" >
```
2020-02-11 21:30:05 +08:00
2018-10-10 18:03:03 -04:00
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
// solution required
```
2020-02-11 21:30:05 +08:00
2018-10-10 18:03:03 -04:00
< / section >
2020-02-11 21:30:05 +08:00