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

时间:2015-03-09 20:19:12

标签: php html css footer

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

请参阅来自Pastebin的代码。

footer.php

index.php

2 个答案:

答案 0 :(得分:1)

当您“包含”footer.php时,您将该代码添加到index.php中。所以既然从index.php调用了css,它应该引用“footer / footer.css”。

答案 1 :(得分:1)

这会产生可怕的HTML代码...... footer.php是一个完整的html页面 - 它有Doctype,html标签,body标签等。 index.php也是如此。 在index.php中包含footer.php将生成无效的html文件,其中html标签位于另一个html标签内(html> body> html> body)......

你无法看到footer.css的原因是因为它被放置在页脚目录中。因此,当你请求index.php时,css的正确路径应该是footer / footer.css,而你只是footer.css(因为footer.php的路径是相对的)。