覆盖背景:在CSS中带有背景色的url

时间:2021-12-01 20:26:05

I'm trying to find a way to override background: url with background-color, but for some reason the background: url is still in front. What should I do instead?

我正在寻找一种方法来覆盖背景:带有背景颜色的url,但是出于某种原因,背景:url仍然在前面。我该怎么做呢?

body {
  background: url("https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg");
  background-color: green;
}

1 个解决方案

#1


4  

If you want to override the background property, override it using the background property rather than background-color:

如果您想要覆盖背景属性,请使用背景属性而不是背景色来覆盖它:

body {
  background: url("https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg");
  background: green; /* This will override the previous property */
}

Alternatively, could add also just add background-image: none in addition to background-color: green:

或者,也可以只添加背景图像:除了背景颜色以外没有:绿色:

body {
  background: url("https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg");
  background-color: green;		
  background-image: none;
}

#1


4  

If you want to override the background property, override it using the background property rather than background-color:

如果您想要覆盖背景属性,请使用背景属性而不是背景色来覆盖它:

body {
  background: url("https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg");
  background: green; /* This will override the previous property */
}

Alternatively, could add also just add background-image: none in addition to background-color: green:

或者,也可以只添加背景图像:除了背景颜色以外没有:绿色:

body {
  background: url("https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg");
  background-color: green;		
  background-image: none;
}