我正在尝试通过 CSS 在网站的背景上显示图像。我希望将图像保存在与 CSS/HTML 文件不同的文件夹中。图像仅显示,如果我将其与 CSS/HTML 文件放在同一文件夹中,并且仅引用其名称。
代码在C:\Users\User\Desktop\project\templates
,图片在C:\Users\User\Desktop\project\pictures
。如果我尝试使用绝对路径,它将不会显示。仅当我将图片放在模板文件夹中时才会显示。
<!--This code works if I place the picture in the template file-->
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("picture.png");
}
</style>
</head>
</html>
<!--This code doesn't work-->
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("C:\Users\User\Desktop\project\pictures\picture.png");
}
</style>
</head>
</html>
使用这个css
Body{
background-image: url("../pictures/picture.png")
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句