css中的背景图像不能正常工作

时间:2018-05-15 10:54:21

标签: html css

我的CSS背景有问题。

这是我的代码:

body{
    background: url("../img/bg.jpg") no-repeat fixed;
    background-size: cover;
}

如果我删除了-image,背景可以正常工作,但是如果我把-image和delete修复它就可以正常工作。

有人可以帮助我吗?

4 个答案:

答案 0 :(得分:1)

background: #ffff url(image) no-repeat top left实际上是

的缩写
background-color: #fff;
background-image: url(image);
background-repeat: no-repeat;
background-position: top left;

background-size属性设置为cover会使background-repeat过时。 如果您设置background-image: url("../img/bg.jpg"),则会使no-repeat过时。 fixed实际上什么都没有。

正如Zuber建议的那样,只需写下长手属性。

body {
  background-image: url("../img/bg.jpg");
  background-attachment: fixed;
  background-size: cover;
}

答案 1 :(得分:0)

更改一些{ path: "", component: AdminLayoutComponent, canActivate: [AuthGuard], children: [ { path: "", canActivate: [RoleGuard], children: [ { path: '', loadChildren: './dashboard/dashboard.module#DashboardModule', data: { roles: ['role.all'] } },...

CSS

答案 2 :(得分:0)

使用background-attachment: fixed;代替fixed



body  {
    background-image: url("https://material.angular.io/assets/img/examples/shiba1.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
}

<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>If you do not see any scrollbars, try to resize the browser window.</p>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

属性background-image不会带多个值,只需要url("../img/bg.jpg")作为值。如果要分配多个值,则应将其分配给background属性。要分离所有背景属性,可以尝试使用此代码。

body {
    background-image: url("../img/bg.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
}