sameed ul hassan
sameed ul hassan

Reputation: 115

How to set css image url in codeigniter

I am using this code for making background image fixed but image url is not working can you tell me what I am missing.

code is written in my view file :

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;
}

Why I am getting "304 error" on all these files? I'm using this code to link these files:

 <script type="text/javascript" src="<?php echo base_url(); ?>assets/jquery/jquery-3.2.1.min.js"></script> 
 <link href=" <?php echo base_url(); ?>assets/css/bootstrap.min.css" rel="stylesheet">
 <link href=" <?php echo base_url(); ?>assets/style/style.css" rel="stylesheet">
 <script type="text/javascript" src="<?php echo base_url();?>/assets/js/bootstrap.min.js"></script>

Upvotes: 0

Views: 9454

Answers (5)

jasinth premkumar
jasinth premkumar

Reputation: 1413

you are missing ""() double quotes.

Use this css for fixed background

body{
 background-attachment: fixed;
 background-image: url(<?php echo base_url();?>./image.jpg);
}

or else , try using this.

background-image: url("../image.jpg");

Upvotes: 3

Danish Ali
Danish Ali

Reputation: 2352

html {

background-image: url('../assests/images/img.jpg') no-repeat center center fixed;

}

Upvotes: 0

SomeRSGuy
SomeRSGuy

Reputation: 590

Here's the way:

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;
}

But I have to say that wolfgang1983's answer is a better practice. Avoid using CSS in your views.

Upvotes: 0

Chaitanya Desai
Chaitanya Desai

Reputation: 323

Use like this:

<div class="profile-pic-feadback" style="background-image:url(<?php echo base_url('images/user.png') ?>)"></div>

you have to used background-image. then it will work. I used this way only.

Upvotes: 0

user4419336
user4419336

Reputation:

Lets say your css file is in assets folder

application

assets

assets > css > example.css

assets > images

system 

index.php

Then try this in the CSS file

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;
}

Of course make sure you have set the base url in the 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/';

Upvotes: 0

Related Questions