gpt4 book ai didi

css - CSS3 是否为 "minimum-size"提供了 "background"属性?

转载 作者:技术小花猫 更新时间:2023-10-29 10:13:59 25 4
gpt4 key购买 nike

我正在使用

background-size: 100%;

使我的背景图片(在 body-tag 中)适合浏览器窗口。

但是是否有 CSS3 背景属性来设置最小尺寸?

或者我需要一些 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%;
}

最佳答案

我觉得你在找

background-size: contain;

background-size: cover;

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

请参阅 MDN 文档 here .

关于css - CSS3 是否为 "minimum-size"提供了 "background"属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10682765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com