【问题标题】:CodeIgniter: CSS: Issue with @importCodeIgniter:CSS:@import 的问题
【发布时间】:2016-01-18 13:30:42
【问题描述】:

我正在尝试让一些第三方 CSS 模板与 CodeIgniter 一起使用。我认为这个问题是由于 CSS 中的 @import 语句,有点不确定确切的原因。

仅加载控制器时一切正常。但是当加载任何通过控制器的东西时,事情就会中断。尾部斜杠会破坏 CSS。

http://example.com/controller = OK
http://example.com/controller/ = Broken

按照推荐的做法,目录结构使用 assets 目录,如下所示:

+
├── application
├── assets
│   ├── css
│   ├── fonts
│   ├── images
+

mod_rewrite 工作正常。我可以直接访问这些文件。

http://example.com/images/picture.jpg = OK
http://example.com/assets/images/picture.jpg = OK

.htaccess

# Rewrite to use the assets directory for site elements
 RewriteCond $1 ^(css|fonts|images)
 RewriteRule ^(.*)$ /assets/$1 [L]

# Rewrite to index.php/URL
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L]

我已经尝试在视图中使用 base_url()。

<link href="<?php echo base_url('css/style.css') ?>" rel="stylesheet" />

但我认为问题在于 css 文件中使用了 @import。

@import url('font-awesome.min.css');
@import url('mobile.css');

谁能提供一些对此问题的见解?

谢谢!

【问题讨论】:

  • 尝试类似url('../css/font-awesome.min.css');主目录上的css beaning文件夹
  • 尽量不要使用url。例如。 @import "font-awesome.min.css";
  • 查看 apache 日志,请求将发送到 /controller/function/assets/etc。经过另一次搜索,我发现这个 question 解决了我的问题。 ' .. .. '

标签: css .htaccess codeigniter mod-rewrite import


【解决方案1】:

查看 apache 日志,我看到了以下内容:

GET /controller/function/css/style.css HTTP/1.1" 404 

经过另一次搜索,我发现这个answer 解决了我的问题。在页面的&lt;head&gt; 部分设置&lt;base href="/" /&gt;

<head>
 <base href="/" />
 ..
 <?php echo link_tag('css/style.css'); ?>
</head>

您可以看到我已更改为 CI link_tag(),它正在工作。 使用原始代码现在也应该可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 2011-08-10
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多