【问题标题】:How do I make a php that links to css file work when included in a nested php当包含在嵌套的 php 中时,如何使链接到 css 文件的 php 工作
【发布时间】:2017-02-10 03:15:51
【问题描述】:

这是我正在使用的结构:

www/
   includes/nav.php
   css/main.css
   css/mobile.css
   css/nav.css
   policies/1000/index.php

1000目录下的index.php可以包含nav.php文件就好了。 nav.php 文件包含指向样式表的链接,根目录下的所有 php 文件都可以正常访问 css 文件:

<link href="/css/nav.css" rel="stylesheet" type="text/css" />
<link href="/css/main.css" rel="stylesheet" type="text/css" />
<link href="/css/mobile.css" rel="stylesheet" type="text/css" />

但是,css 没有出现在 policy/1000/index.php 中,我认为这是因为 nav.php 文件试图在 policy/1000/css/ 中找到 css 文件。我该如何补救?

【问题讨论】:

  • 你需要使用绝对网址:|因为 nav.php 可以从许多路径加载:|
  • 您的 www 目录服务器是否作为根目录?如何在浏览器中访问文件?
  • 如何将nav.php 包含到index.php 中?

标签: php css


【解决方案1】:

如果您在许多文件中包含nav.php,则可以使用您网站的网址,因此,在nav.php

<link href="http://domain.com/css/your_file.css" rel="stylesheet" />

注意:HTML 的默认样式表类型是text/css,无需添加该属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-30
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 2015-06-30
    • 1970-01-01
    相关资源
    最近更新 更多