freeCodeCamp/guide/chinese/css/background-size/index.md

35 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Background Size
localeTitle: 背景大小
---
## 背景大小
background-size属性指定背景图像的大小。您可以设置长度或百分比第一个值是宽度第二个值是高度。您还可以使用以下5个关键字值之一
```css
.auto {background-size: auto;}
.cover {background-size: cover;}
.contain {background-size: contain;}
.initial {background-size: initial;}
.inherit {background-size: inherit;}
/* Percentage and pixel can also be used */
.pixel {background-size: 50px 50px;}
.percentage {background-size: 50% 50%;}
```
要在多个背景图像上设置此属性,请用逗号分隔值:
```css
.multiple {
background-image: url(1.png), url(2.png);
background-size: 3px 3px, cover;
}
```
#### 更多信息:
文档: [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
CSS-Tricks [背景大小](https://css-tricks.com/almanac/properties/b/background-size/)
浏览器支持: [caniuse](http://caniuse.com/#search=background-size)