Domanda

This question has been asked several times, but have not found the right answer which will work on my project.

my CSS file liking

<link rel="stylesheet" type="text/css" href="assets/css/style.css"/>

The css file is in:

-main_directory
  -Application
  -Assets
    -css
       -style.css
  -System

I also tried to link css using base_url href="<?php echo base_url('assets/css/style.css');?>" but it doesn't work for me.

So what is the problem? Can anyone help?

È stato utile?

Soluzione

Your structure should be like this

myproject
  application
  assets
    css
       style.css
 system

autoload url helper in config/autoload.php

$autoload['helper'] = array('url');

Now

<link href = '<?php echo base_url()?>/assets/css/style.css'>

This should work. Make sure your spellings are correct and see the casd sensitive issue if you are using linux.

Altri suggerimenti

is your base_url() method config properly? Check here...

ci_app_folder/config/config.php

if yours is located in c:/xampp/htdocs/ci_app_name

$config['base_url'] = 'localhost/ci_app_name'; //or localhost:90/ci_app_name if you had changed port

Then you can use this

<link rel="stylesheet" type="text/css"  href="<?php echo base_url('assets/css/style.css'); ?>" >

You can also set base_url() empty . If you haven't uploaded to web hosting/server.

Try this once -
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/css/style.css" />

You could place the custom css links like this :

    background-image:url(../../); moving back to the directory you want

using CI you need to use in-line css: eg.

    <div style = background-image: url(<?php echo base_url();?>)assets/images/>
    </div>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top