3
body {
    background: url('../../asset/background.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

这是我的背景图像代码。我希望在调整浏览器大小时图像不能调整大小。

4

3 回答 3

4

你不应该使用background-size:cover;. 使用该 CSS,您可以告诉浏览器您希望背景图像扩展以覆盖整个背景区域。

如果您希望背景图像居中且不调整大小,只需执行以下操作:

body {
    background: url('../../asset/background.jpg') no-repeat center center;
}

您可以以任何您喜欢的方式放置背景,这里有更多选项

于 2012-12-28T23:18:04.303 回答
3

尝试设置背景大小:

background-size: 100px 100px;
于 2012-12-28T23:18:37.893 回答
-1

设置background-sizetocover占用div的空间。看到这个

删除该background-size属性,它将正常工作。

于 2012-12-28T23:22:31.047 回答