【问题标题】:How to include php page which include also a css file?如何包含包含 css 文件的 php 页面?
【发布时间】:2015-05-11 03:22:44
【问题描述】:

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

请参阅 Pastebin 的代码。

footer.php

index.php

【问题讨论】:

  • 请在此处粘贴代码
  • @Dagon 如果他们将其粘贴到您的评论旁边,空间不足:p
  • @Fred-ii- 不是这里这里,而是那里这里,你这个傻熊。
  • @Dagon 哦,“那个”那里“这里”。我真是个傻

标签: php html css footer


【解决方案1】:

当您“包含”footer.php 时,您就是将该代码添加到您的 index.php 中。因此,由于从 index.php 调用 css,它应该引用“footer/footer.css”。

【讨论】:

    【解决方案2】:

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

    你看不到footer.css的原因是因为它放在footer目录下。因此,当您请求 index.php 时,css 的正确路径应该是 footer/footer.css,而您得到的只是 footer.css(因为 footer.php 的路径是相对的)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 1970-01-01
      • 2012-02-13
      • 2010-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多