base_url() 不适用于 CSS 文件...
这是我的 php :
<link rel="stylesheet" type="text/css" href="<?=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 时,它没有显示......
已经解决了,谢谢大家...:]
我在视图文件夹中创建 php 文件,如下所示:
<?php header("content-type: text/css"); ?>
body {
background:url(<?=base_url()?>img/background.png);
}
我加载我刚刚在控制器上使用函数创建的 php 文件,然后链接它:
<link type="text/css" rel="stylesheet" href="<?=base_url()?>control/style.php"/>
已经工作了,谢谢大家...
你应该这样做
文件的结构
myapp/
application/
system/
css/
img/
然后在CSS中写下这个
body {
background:#356aa0 url(../img/background.png) repeat-x;
color:#fff;
}
现在称之为
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/style.css"/>
这是标准的做法。此外,您的 css 不是动态的,因此您不必担心其中使用的 php 代码。我在答案中提出的结构肯定会正确使用样式并加载图像。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)