【问题标题】:How to include/link css (and html) from sub directories?如何从子目录中包含/链接css(和html)?
【发布时间】:2018-03-21 23:07:16
【问题描述】:

我已经建立了一个非常简单的网页,其中包含一些 css 文件和一些由其他人提供给我的 html 包含文件。

我服务器上的目录树如下所示:

css/ global.css site.css includes/ header.html footer.html nav.html index.html subdir/ index.html

我的所有 html 文件(includes 目录中的文件除外)都包含此类内容(除其他外)

... <link href="css/global.css" rel="stylesheet" /> <link href="css/site.css" rel="stylesheet" /> <body> <!--#include file="includes/header.html" /> ... </body> ...

此设置适用于我拥有的顶级index.html 页面,但在其他任何页面(即subdir/index.html)上都失败了。我在浏览器中收到一条消息:

[an error occurred while processing this directive]

我知道 apache 网络服务器只是找不到 css 和包含文件(我已经检查了日志),但我不知道在哪里告诉它去寻找它们。我尝试过这样的事情:

<link href="../css/global.css" rel="stylesheet" />

但它也不起作用。

我是网络编程的新手,所以如果这是过于基本的东西,我深表歉意。

【问题讨论】:

    标签: html css apache


    【解决方案1】:

    你可能想要这样的东西:

    &lt;link rel="stylesheet" type="text/css" href="/css/global.css" /&gt;

    路径以“/”开头,表示根目录,然后是文件的确切路径,当您从子目录中调用它时,或者当文件位于同一目录中时,不使用“/”作为 html 文件。

    您可能会发现更多here

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多