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

1.0 KiB
Raw Blame History

title localeTitle
Background Size 背景大小

背景大小

background-size属性指定背景图像的大小。您可以设置长度或百分比第一个值是宽度第二个值是高度。您还可以使用以下5个关键字值之一

.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%;} 

要在多个背景图像上设置此属性,请用逗号分隔值:

.multiple { 
    background-image: url(1.png), url(2.png); 
    background-size: 3px 3px, cover; 
 } 

更多信息:

文档: MDN

CSS-Tricks 背景大小

浏览器支持: caniuse