我使用什么路径在codeigniter中调用背景图像 [英] What path do I use to call a background image in codeigniter
问题描述
这是我的根结构:
在css文件夹下,我有文件style.css
And under the folder css, I have the file style.css
我加载了我的文件像这样的CSS文件:
I load my CSS file like this:
<link rel="stylesheet" href="<?php print asset_url()?>css/style.css">
我创建了一个具有此功能的帮助者asset_url_helper:
I created a helper asset_url_helper that has this function:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('asset_url()')) {
function asset_url()
{
return base_url().'assets/';
}
}
我的.htacces文件:
And my .htacces file:
Deny from all
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
加载CSS文件就像魅力一样,没问题。
Loading the CSS file works like a charm, thats no problem.
现在我想用我的样式CSS调用背景图像:
Now I want to call a background image from my style CSS something like this:
body {
background-image: url('/assets/img/bg-admin.jpg');
}
但这不起作用
有人能告诉我如何从CSS调用图像文件吗?
Can someone tell me how I call the image file from CSS?
推荐答案
背景-image:url()
在CSS中比较有效。
background-image: url()
in CSS works relatively.
试试这个:
body {
background-image: url('../img/bg-admin.jpg');
}
这假设您的css文件位于assets / css而不是sub它的文件夹。
This is assuming that your css file is in assets/css and not a sub folder of it.
希望这会有所帮助!
这篇关于我使用什么路径在codeigniter中调用背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!