我的文件夹设置
-src/main/html/index.html
-src/main/css/global.css
以防它是相关的,我有 apache24 设置来寻找
DocumentRoot "/home/master/Documents/projects/SCI/src/main/html.
最后,在我的 index.html 中有
<link rel="stylesheet" type="text/css" href="../css/global.css" />
我的问题是我的 css 不起作用,除非我将我的 global.css 放在 html 文件夹中并直接执行“href =”global.css。除此之外,我尝试将 href 设置为“/css/global.css”、“css/global.css”、“/../css/global.css”、“global.css”和“/css/global.css”。我应该让我的 href 成为什么我的 CSS 代码
编辑:它似乎在运行时删除了“..”。如果我检查网页中的元素,它会显示“在此服务器上未找到请求的 URL/css/global.css”
最佳答案
已找到答案,这是一个 Apache“问题”。 Apache 不会让您比“DocumentRoot”更进一步。因此,通过将我的根设置为“.../html”,我不能看过去“.../html”,只能向前看;因此,无论我在代码中添加了多少个“../”,我都无法查看 html 文件。
解决方案是将 DocumentRoot 设置为“.../src/main/”并导航到 localhost/html。这样,“../css/global.css”现在可以返回查看 css 文件夹。
关于html - 在不同的文件夹中调用 css 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47735581/