这是我的目录结构:
-根
--文档
---doc1.php
--包括
---header.php
---footer.php
---css.css
--index.php
在我的标题中,我像这样链接到我的 CSS 文件:
<link href="includes/styling.css" type="text/css" rel="stylesheet" />
这适用于 index.php,因为它是正确的路径 (root/includes/css.css)。
但对于 doc1.php,这不是正确的路径。 (root/docs/includes/css.css).
如何在保留一个包含该行代码的 header.php 文件的同时修复此问题?有没有办法强制路径从根目录开始?
最佳答案
使用绝对路径而不是相对路径。
<link rel="stylesheet" type="text/css" href="/root/includes/css.css" />
关于html - CSS 文件未在子目录中链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1731958/