Css 锁定背景图像大小

Css 锁定背景图像大小,css,background-image,Css,Background Image,我想知道如何锁定div背景图像的大小。我希望能够放大页面的大小,同时保持背景图像的大小不变,只改变裁剪因子。尝试做类似的事情 我以前用过,它们都很好用。如果你阅读了每种方法的优缺点,你就可以决定哪种方法适合你的网站 或者,如果您想避免上述错误,您可以使用。您可以使用 //this will scale the background image as large as possible to cover the whole div background-size:cover; //for fix

我想知道如何锁定div背景图像的大小。我希望能够放大页面的大小,同时保持背景图像的大小不变,只改变裁剪因子。尝试做类似的事情

我以前用过,它们都很好用。如果你阅读了每种方法的优缺点,你就可以决定哪种方法适合你的网站

或者,如果您想避免上述错误,您可以使用。

您可以使用

//this will scale the background image as large as possible to cover the whole div
background-size:cover;

//for fixed positioning
background-attachment:fixed;
//to make it center (or center top, depends on your need)
background-position:center center;

有关背景尺寸的更多信息,您可以阅读文章

不要只添加链接,描述实际技术,并添加额外的链接。如果你链接到的网站发生了变化,你的答案将变得毫无用处…谢谢!工作得很好。
//this will scale the background image as large as possible to cover the whole div
background-size:cover;

//for fixed positioning
background-attachment:fixed;
//to make it center (or center top, depends on your need)
background-position:center center;