Css 如何在根目录上创建文件夹的路径?
这是我的目录:Css 如何在根目录上创建文件夹的路径?,css,path,directory,Css,Path,Directory,这是我的目录: /myweb /css style.css /img icon.png index.php .htaccess 我需要在style.css中调用icon.png。我已经测试了很多案例,但没有一个有效: // style.css url(../img/icon.png) url(./img/icon.png) url(/img/icon.png) url(img/icon.png) url(../icon.png)
/myweb
/css
style.css
/img
icon.png
index.php
.htaccess
我需要在style.css
中调用icon.png
。我已经测试了很多案例,但没有一个有效:
// style.css
url(../img/icon.png)
url(./img/icon.png)
url(/img/icon.png)
url(img/icon.png)
url(../icon.png)
url(./icon.png)
有人知道正确的路径吗?调用url(../img/icon.png)
是正确的。
您是否尝试从其他地方调用图像,例如背景:
body {
background-image: url(../img/icon.png);
}
另外,请检查
.htaccess
中的配置,您使用什么url访问myweb?@Corporalishttp://localhost/myweb
在这种情况下,您可以使用url(../img/icon.png”)
。路径将是相对于样式表的。当然,您也可以使用url(“/myweb/img/icon.png”)
从根目录开始,尽管我不建议这样做,因为它可能需要在不同的环境中工作,但这是一个值得的测试。如果这不起作用,那就值得多看一点css。