我正在使用此代码修复背景图像但图像网址不起作用你能告诉我我缺少什么。
代码写在我的视图文件中:
<div id="tags"></div>
为什么我在所有这些文件上收到“304错误”?我正在使用此代码链接这些文件:
html {
background: url(<?php echo base_url();?>assets/images/img.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
答案 0 :(得分:2)
您缺少""
()双引号。
将此CSS用于固定背景
body{
background-attachment: fixed;
background-image: url(<?php echo base_url();?>./image.jpg);
}
或者, 尝试使用它。
background-image: url("../image.jpg");
答案 1 :(得分:0)
像这样使用:
<div class="profile-pic-feadback" style="background-image:url(<?php echo base_url('images/user.png') ?>)"></div>
你必须使用背景图像。然后它会工作。我只是用这种方式。
答案 2 :(得分:0)
让我们说你的css文件在资产文件夹
application
assets
assets > css > example.css
assets > images
system
index.php
然后在CSS文件中尝试这个
body {
background: url('../images/img.jpg') no-repeat center center fixed;
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
当然要确保在config.php中设置了基本网址
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://localhost/yourproject/';
答案 3 :(得分:0)
html {
background-image: url('../assests/images/img.jpg') no-repeat center center fixed;
}
答案 4 :(得分:0)
这是方式:
html {
background-image: url('<?= base_url("assets/images/img.jpg");?>') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
但我必须说wolfgang1983's answer是一种更好的做法。避免在视图中使用CSS。