这是我的根文件夹:
index.php
stylesheets(folder) --->main.css
includes(folder) --->header.php
folder1 (folder) --->page1.php
这是“header.php”的链接部分(来自包含文件夹):
<link href="stylesheets/main.css" rel="stylesheet" type="text/css" />
这是 index.php 的一部分:
<?php include "includes/header.php"; ?>
这是 page1.php 的一部分(来自 folder1):
<?php include "../includes/header.php"; ?>
问题是,当我打开 index.php 时一切正常。至于/folder1/page1.php,它看不到样式,但看到header.php 的内容。也就是说不带main.css。很可能是因为 link href="stylesheets/main.css"rel="stylesheet"type="text/css"
有帮助吗?
最佳答案
因为您从多个级别访问文件,所以您应该使用绝对路径。
所以 href="http://domain.com/stylesheets/main.css"
或 href="/stylesheets/main.css"
但这只有在您将它放在域的顶级时才有效(第二个,也是我推荐的那个)。
关于php - HTML "link href"如何从不同的文件夹中调用相同的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10420888/