代码Igniter:base_url()在CSS文件不工作 [英] Code Igniter : base_url() at CSS file doesn't work

查看:217
本文介绍了代码Igniter:base_url()在CSS文件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

base_url()在CSS文件中不起作用...



这里是我的php:

 < link rel =stylesheettype =text / csshref =<?= base_url()?> css / style.css/> 
< body>
< / body>

这里是我的css / style.css:

  body {
background:#356aa0 url(<?= base_url()?> img / background.png)repeat-x;
color:#fff;
}

文本颜色变为白色,但图像不显示。 ..
如果我使用url(../ img / background.png),它显示...
但是当我打开url localhost / project / index.php / control / function / var1 / var2,它不会显示...



它是解决,感谢每一个...:]



i在视图文件夹中创建php文件,如下所示:

 <?php header(content-type:text / css ); > 

body {
background:url(<?= base_url()?> img / background.png);
}

并且我加载php文件我刚刚在控制器的功能,然后i link it:

 < link type =text / css =stylesheethref =<?= base_url()?> control / style.php/> 

这是工作,谢谢你们...



您的文件结构

pre> myapp /
application /
system /
css /
img /
pre>

在css中写入

  body {
background:#356aa0 url(../ img / background.png)repeat-x;
color:#fff;
}

现在称为

 < link rel =stylesheettype =text / csshref =<?= base_url()?> css / style.css/> 

这是标准的做法。另外你的css不是动态的,所以你不必担心php代码使用它。在答案中提出的结构肯定会正确使用样式并加载图像。


base_url() doesn't work at CSS file...

here's my php :

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

here's my css/style.css :

body {
  background:#356aa0 url(<?=base_url()?>img/background.png) repeat-x;
  color:#fff;
}

the text color change to white, but the image doesn't show up... if i use url(../img/background.png), it show up... but when i open url localhost/project/index.php/control/function/var1/var2, it doesn't show up...

It's Solved, Thanks every one... :]

i make php file at view folder like this :

<?php header("content-type: text/css"); ?>

body {
    background:url(<?=base_url()?>img/background.png);
}

and i load the php file i just make with function at controller, and then i link it :

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

It's work, Thanks guys...

解决方案

You should do it like this

Structure of your files

myapp/
    application/
    system/ 
    css/
    img/

And in css write this

body {
  background:#356aa0 url(../img/background.png) repeat-x;
  color:#fff;
} 

And now call it

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

That is the standard way of doing it. Also your css is not dynamic so you dont have to worry about php code using in it. The structure i presented in the answer will surely use the styles correctly and load the images.

这篇关于代码Igniter:base_url()在CSS文件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆