-1

我正在尝试在我的网站上设置背景图片,目前我正在使用 localhost 进行测试,但我无法设置它。我将图片放在与 index.html 相同的文件中。名称也与代码“background2.jpg”中的名称相同。

这是我在 css 文件中的代码:

body
{
background:url("background2.jpg") no-repeat center center   fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
user-select: none;
-moz-user-select: none;
overflow: hidden;   
}
4

4 回答 4

1

我刚刚使用您的 css 和我的图像创建了 index.html,它位于同一个文件夹中,并且可以正常工作。可能您的网络服务器设置有问题。

于 2013-10-03T10:08:04.827 回答
0

代码很好。如果所有文件都在同一个目录中,那就没问题了。

可以说是显而易见的事情,但很可能是您的案例中有旧网页。你试过按Ctrl+F5吗?这会刷新您的现金记忆。

于 2013-10-03T13:51:49.983 回答
-1

你需要这个

body{
height:100%;
width:100%;
}

尝试这个..

于 2013-10-03T10:05:22.533 回答
-2

尝试这个:

body
{
width: 100%;
height: 100%;
background:url("background2.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
user-select: none;
-moz-user-select: none;
overflow: hidden;   
}
于 2013-10-03T10:05:59.410 回答