如何包含还包含 css 文件的 php 页面?

How to include php page which include also a css file?

我在 Whosebug 上搜索了很多并找到了相关答案,但这些都不是这个问题的完美解决方案。 我有一个名为 root 的目录。在根文件夹中有 1 个名为 footer 的文件夹和 1 个名为 index.php 的文件 在页脚目录中有 2 个名为 footer.php 和 footer.css 的文件。我想包含来自 footer.php 的文件 index.php 页。 footer.php 页面有样式表 link 和 footer.css 页面。但是index.php页面找不到footer.css 页。

请查看来自 Pastebin 的代码。

footer.php

index.php

当您 "include" footer.php 时,您正在将该代码添加到您的 index.php。因此,由于 css 是从 index.php 调用的,它应该引用 "footer/footer.css".

这将产生可怕的 html 代码... footer.php 是一个完整的 html 页面 - 它有文档类型、html 标签、正文标签等。 index.php 也是如此。 在 index.php 中包含 footer.php 将产生无效的 html 文件,在另一个 html 标签内包含 html 标签(html > body > html > 正文) ...

之所以你看不到footer.css是因为它被放置在页脚目录中。因此,当您请求 index.php 时,css 的正确路径应该是 footer/footer.css,而您得到的只是 footer.css(因为 [=15 的路径=] 是相对的)。