css - 我使用什么路径在 codeigniter 中调用背景图像

标签 css image codeigniter

这是我的根结构:

enter image description here

在文件夹 css 下,我有文件 style.css

我像这样加载我的 CSS 文件:

<link rel="stylesheet" href="<?php print asset_url()?>css/style.css">

我创建了一个具有此功能的助手 asset_url_helper:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('asset_url()')) {
    function asset_url()
   {
    return base_url().'assets/';
   }
 }

还有我的 .htaccess 文件:
Deny from all
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

加载 CSS 文件就像一个魅力,那没问题。

现在我想从我的样式 CSS 中调用背景图像,如下所示:
body {
    background-image: url('/assets/img/bg-admin.jpg');
}

但这不起作用

有人能告诉我如何从 CSS 调用图像文件吗?

最佳答案

background-image: url()在 CSS 中相对工作。

尝试这个:

body {
    background-image: url('../img/bg-admin.jpg');
}

这是假设您的 css 文件位于 assets/css 而不是它的子文件夹。

希望这可以帮助!

关于css - 我使用什么路径在 codeigniter 中调用背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26989533/

相关文章:

apache - htaccess 使用 index.php 重定向到 https

php - 无法使用 Codeigniter 更新数据库中的数据

javascript - Wordpress 子主题模板不适用于外部 jquery/javascript 函数

html - 容器的 IE8 问题?

html - 如何让三个水平图像并排显示

c# - 在 WPF 图像控件上设置背景图像?

php - 一些字符在 POST 期间编码,而另一些则没有

HTML 和 CSS 布局

html - 内联 SVG 过滤器作为数据 URI

html - 在图像上叠加三个不同的图像,只先叠加