--- id: 587d78b1367417b2b2512b09 title: Make an Image Responsive challengeType: 0 videoUrl: '' localeTitle: 使图像响应 --- ## Description
使用CSS响应图像实际上非常简单。而不是对元素应用绝对宽度: img { width: 720px; }您可以使用:
img {
最大宽度:100%;
显示:块;
身高:自动;
}
100%的max-width属性会缩放图像以适合其容器的宽度,但图像的拉伸宽度不会超过其原始宽度。将display属性设置为block会将图像从内联元素(默认值)更改为其自身行上的块元素。 auto的height属性保持图像的原始宽高比。
## Instructions
添加img标记的样式规则,使其响应其容器的大小。它应该显示为块级元素,它应该适合其容器的整个宽度而不拉伸,并且它应该保持其原始的宽高比。
## Tests
```yml tests: - text: 您的img标记的max-width设置为100%。 testString: 'assert(code.match(/max-width:\s*?100%;/g), "Your img tag should have a max-width set to 100%.");' - text: 你的img标签应该有一个display设置阻止。 testString: 'assert($("img").css("display") == "block", "Your img tag should have a display set to block.");' - text: 你的img标签的height应该设置为auto。 testString: 'assert(code.match(/height:\s*?auto;/g), "Your img tag should have a height set to auto.");' ```
## Challenge Seed
```html freeCodeCamp stickers set ```
## Solution
```js // solution required ```