简体   繁体   English

如何在子目录中使用背景图像?

[英]How to use background-image with subdirectory?

I am having issues setting background-image when I move the picture into an image folder. 将图片移到图像文件夹时,设置背景图像时出现问题。

When my folder structure looks like this 当我的文件夹结构如下所示时

 Site
   |
   |+ index.html
   |
   |+ style.css
   |
   |+ image.jpg
   |
   |+ images
          |
          |other images

and in my stlye.css file I have the following which is working as I would expect and the background image displays correctly 并且在我的stlye.css文件中,我可以正常运行以下内容,并且背景图像可以正确显示

#topContainer {
    background-image: url("image.jpg");
    height: 400px;
    width: 100%;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    color: #f2f2f2;
    text-shadow: -0.3px -0.3px 0 #73736d, 0.3px -0.3px 0 #73736d, -0.3px 0.3px 0 #73736d, 0.3px 0.3px 0 #73736d;
}

However, if I move the image.jpg to the images folder and change the background-image line in the css to be any of the following the image does not show up anymore 但是,如果我将image.jpg移到images文件夹,并将css中的background-image行更改为以下任意一项,则该图像不再显示

background-image: url("images/image.jpg");
background-image: url("/images/image.jpg");
background-image: url('images/image.jpg');
background-image: url('/images/image.jpg');

I thought that any of these should work, but is there a different way I am supposed to input a file path to the background-image? 我以为所有这些都应该起作用,但是我应该以另一种方式输入背景图像的文件路径吗?

试试看: background-image: url('@/images/image.jpg');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM