Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 将背景属性重构为一行会使图像消失_Css_Background Image_Background Size - Fatal编程技术网

Css 将背景属性重构为一行会使图像消失

Css 将背景属性重构为一行会使图像消失,css,background-image,background-size,Css,Background Image,Background Size,我正在尝试清理后台属性的CSS。当我单独列出每个属性时,一切都按预期进行。然而,当我试图将其重构为一行时,图像消失了。我相信这与backgroundsize属性有关,但在重构的解决方案中我还没有弄清楚。任何帮助都将不胜感激 工作代码 .bg { content: ""; height: 100vh; background-image: url("../../assets/mountain.jpg"); background-position

我正在尝试清理后台属性的CSS。当我单独列出每个属性时,一切都按预期进行。然而,当我试图将其重构为一行时,图像消失了。我相信这与backgroundsize属性有关,但在重构的解决方案中我还没有弄清楚。任何帮助都将不胜感激

工作代码

.bg {
  content: "";
  height: 100vh;
  background-image: url("../../assets/mountain.jpg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
  opacity: 0.9;
}
尝试重构

.bg {
  content: "";
  height: 100vh;
  background: url("../../assets/mountain.jpg") center cover no-repeat;
  position: relative;
  opacity: 0.9;
}
这应该起作用:

background: url("../../assets/mountain.jpg") no-repeat center / cover;
背景大小需要以“/”字符开头(我认为需要在结尾处加“/”。

这应该可以:

background: url("../../assets/mountain.jpg") no-repeat center / cover;

背景大小需要在前面加一个“/”字符(我认为应该在末尾加上)。

这是否回答了您的问题?这回答了你的问题吗?这就是诀窍!谢谢你,这就是诀窍!非常感谢。