CSS3是否为"背景"提供了"最小尺寸"属性?

fra*_*sMi 20 css background css3

我正在使用

background-size: 100%;
Run Code Online (Sandbox Code Playgroud)

使我的背景图像(在body标签中)适合浏览器窗口.

但是有没有CSS3 background-property来设置最小尺寸?

或者我需要一些div-"技巧",如:

<div id="bg">
    <img src="images/bg.jpg" alt="">
</div>

#bg {
    position:fixed;
    top:-50%;
    left:-50%;
    width:200%;
    height:200%;
}
#bg img {
    position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
    margin:auto;
    min-width:50%;
    min-height:50%;
}
Run Code Online (Sandbox Code Playgroud)

Raa*_*aab 29

我想你在找

background-size: contain;
Run Code Online (Sandbox Code Playgroud)

要么

background-size: cover;
Run Code Online (Sandbox Code Playgroud)

区别在于cover指定背景图像应尽可能小,同时保持其纵横比.contain另一方面,指定背景图像应尽可能大.

请在此处查看MDN文档.