把background-size: contain;放在background: url(“xxxx.png”) no-repeat;后面就行了。
.title {
//这样是不会生效的
background-size: contain;
background: url("xxx.png") no-repeat;
}
.title {
//这样才会生效
background: url("xxx.png") no-repeat;
background-size: contain;
}

本文介绍了一种在CSS中正确设置背景图片大小的方法。通过将background-size属性设置为contain,并确保其位于background:url之后,可以实现背景图片的恰当显示,且保持图片原始宽高比。
7147

被折叠的 条评论
为什么被折叠?



