【发布时间】:2022-11-10 18:31:19
【问题描述】:
我想使用 CSS 'background-image' 选择器添加背景图像。 当我尝试从另一个目录添加图像时,图像未加载,我一定是缺少文件路径约定。请帮我 语法是:
body {
background-image: url('tree.png'); /*(image is in the same folder the code is)*/
background-repeat: no-repeat;
}
但是当我使用下面的代码时;我没有图像。
body {
background-image: url('G:/Web_Development/bg_img/tree.png');
background-repeat: no-repeat;
}
【问题讨论】:
-
你的html文件在哪里?
-
html 文件在
Web_Development中吗? -
试试
background-image: url('./tree.png') -
如果正文中没有任何内容,则看不到背景图像。
-
@sampat-aheer 如果该解决方案有效,您能否回复我。如果没有,那么我将以不同的视角工作