问题
This is my root structure:

And under the folder css, I have the file style.css
I load my CSS file like this:
<link rel="stylesheet" href="<?php print asset_url()?>css/style.css">
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/';
}
}
And my .htacces file:
Deny from all
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Loading the CSS file works like a charm, thats no problem.
Now I want to call a background image from my style CSS something like this:
body {
background-image: url('/assets/img/bg-admin.jpg');
}
But this doesn't work
Can someone tell me how I call the image file from CSS?
回答1:
background-image: url()
in CSS works relatively.
Try this:
body {
background-image: url('../img/bg-admin.jpg');
}
This is assuming that your css file is in assets/css and not a sub folder of it.
Hope this helps!
回答2:
codeigniter will take the base_url. your url is http://localhost/rscms/external/bootstrap/css/style.css you will to go back to bootstrap first come out from style.css then css then bootstrap
background-image: url('../../../img/bg-admin.jpg');
来源:https://stackoverflow.com/questions/26989533/what-path-do-i-use-to-call-a-background-image-in-codeigniter