【问题标题】:Unable to load css file in codeigniter无法在codeigniter中加载css文件
【发布时间】:2012-09-29 13:35:30
【问题描述】:

我是 codeigniter 的新手,正在尝试学习它,但我无法加载或使用我的 css 样式表进行布局。我加载CSS文件的方法是我在互联网上找到的,但没有奏效。请提出一些建议。

这是我的代码

<html>

<head>
<title>homePage</title>

 <!--[if lte IE 6]>
    <style type="text/css">
    img, div { behavior: url(http('<?php echo $base_url; ?>images') }
    </style>
<![endif]-->


<!--[IF lte IE 6]>

<link rel="stylesheet" href="<?php echo $base_url; ?>/css/homestyle.css" type="text/css" />

<![endif]-->
</head>

 <body >


 <div id="page">
 <div id="menulinks">
    <a class="active" href="#"><span>Home</span></a>
    <a href="#"><span>Services</span></a>
    <a href="#"><span>About Us</span></a>
    <a href="#"><span>Contact Us</span></a>
</div>
<div id="header">

</div>
          <div class="active" id="contentarea">
  <br>
 <br> 
 </div>

 </div>
</body>

</html>

【问题讨论】:

  • 你的css文件放在哪里了?
  • 我的 css 文件在我的 www/codeiginitor/res/css/style.css 中
  • res 文件夹和 css 文件夹是我制作的,我将样式表放入其中。在视图文件中我这样写。

标签: html css codeigniter


【解决方案1】:
<!--[IF lte IE 6]>
<link rel="stylesheet" href="<?php echo $base_url; ?>/css/homestyle.css" type="text/css" />
<![endif]-->

这是一个注释,大多数浏览器不会解析里面的内容。只能在 IE 下使用。您需要将&lt;link&gt; 放在 cmets 之外:

<link rel="stylesheet" href="<?php echo $base_url; ?>/css/homestyle.css" type="text/css" />

【讨论】:

  • 我现在在我的视图文件中写了这样的标签.. 仍然没有工作。我的 css 文件位于:www/codeignitor/res/css/homestyle.css
  • 一定是有路径的东西。尝试以 / 开头 href="/res/css/homestyle.css"
  • 现在我的 css 样式已加载,但我无法看到我的背景图片。我的图像在 css 文件中。 #header { 宽度:900px;高度:119px;背景图像:url(/images/header.png);填充顶部:70px;填充底部:8px;填充右:-20px; } 但他们没有被加载.. images 文件夹放在 www/codeignitor/images 我错了
  • 图片路径必须是相对于 css 位置的。如果 css 文件是 ww/codeignitor/res/css/ww/codeignitor/images 中的图像,这意味着 css 文件的相对路径是 ../../images/ 并且应该如下所示:background-image:url(../../images/header.png);
  • 对不起,我没有理解你的意思...你能详细说明一下吗?
【解决方案2】:

包裹在&lt;!--[if lte IE 6]&gt; 中的HTML 只会被IE6 和更早版本解析——这对您的行为属性非常有用,但可能会限制homestyle.css。试试这个:

 <head>
    <title>homePage</title>
    <base href="<?= $base_url;?>">
    <!--[if lte IE 6]>
        <style type="text/css">
            img, div {
                behavior: url(images);
            }
        </style>
    <![endif]-->
    <link rel="stylesheet" href="css/homestyle.css" type="text/css" />
</head>

在你的 cmets 之后编辑:

嗯,是的,我假设您已经从您的问题中定义了该变量。进入config/autoload.php 并将'url' 键添加到$autoload['helper'] 数组:

例如:$autoload['helper'] = array('url', 'file', 'your_other_helpers...');

然后把上面的HTML改成&lt;base href="&lt;?= site_url();?&gt;"&gt;

【讨论】:

  • 我试过但得到这个错误.. 遇到 PHP 错误 严重性:通知消息:未定义变量:base_url 文件名:core/Loader.php(829) : eval()'d code跨度>
猜你喜欢
  • 2016-08-26
  • 2015-05-28
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-08
相关资源
最近更新 更多