【问题标题】:How do I include a PHP url in a CSS file?如何在 CSS 文件中包含 PHP url?
【发布时间】:2013-03-18 21:06:56
【问题描述】:

我在 php (codeigniter) 中有一个扩展版 bootstrap 的链接:

<link href="<?= base_url() . RESOURCE_PATH . 'css/extended_bootstrap.' ?>" rel="stylesheet" /> 

在我的 CSS 文件中,我有:

input[type="file"]
{
behavior: url(PIE.htc);
}

PIE.htc 的网址必须与root 相关。如何格式化 url,使其相对于 root 而不是我的 bootstrap.css 扩展版本?

【问题讨论】:

  • 以斜杠 / 开头——指向您的域根目录。
  • 不可能在 CSS 文件中包含有效的 PHP url,是吗?

标签: php css


【解决方案1】:

使用../ 将“向上”移动一个级别。您可以将它们绑定在一起以移动多个级别。

例如...

ROOT --> CSS --> style.css
ROOT --> pie.htc

要向后移动一个级别,您可以使用../pie.htc

【讨论】:

    【解决方案2】:

    如果您的文件夹结构是:

    YourAppFolder/
        application/
               public/
                   css/
                   img/
             system/
    

    然后在你的视图中使用它:

    <link rel="stylesheet" type="text/css" href="<?=base_url()?>public/css/style.css"/>
    

    在 css 中使用它作为图像:

    background:#356aa0 url(../img/background.png) repeat-x;
    

    【讨论】:

      猜你喜欢
      • 2014-12-07
      • 1970-01-01
      • 2023-03-06
      • 2015-05-11
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 2012-08-10
      • 2011-12-24
      相关资源
      最近更新 更多