• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSS file is not loading

Hello, I am trying to implement a template I found into CodeIgniter. However, the CSS file will not load. The view appears to load, but without the CSS file. Here is the line for loading it, can anyone help? The CSS file is in the View folder.

<link rel="stylesheet" type="text/css" href="action.css" media="screen,projection" />

its a path issue

instead of declaring
<link rel=“stylesheet” type=“text/css” href=“action.css” media=“screen,projection” />

copy your css where the index.php and system folder is

for example


and declare your css as follow

<link rel=“stylesheet” type=“text/css” href=“<?=base_url()?>css/action.css” media=“screen,projection” />

The path to your file is probably wrong. Here is the syntax I use to include css files, it works no matter where the files are located

<link rel="stylesheet" href="<?=base_url()?>_css/thickbox.css" type="text/css" />

Make sure that base_url is set correctly in your config.php. My value is

$config['base_url']    = "http://localhost:8888/site_name/";

better and easy way to use link tag with CI html helper link_tag() helper function

echo link_tag('css/mystyles.css');

check user guide


Thanks for the help so far but I am still getting this error message: Fatal error: Call to undefined function base_url() in C:\wamp\www\system\application\views\action_view.php on line 8

Line 8:
<link rel="stylesheet" type="text/css" href="<?=base_url()?> css/action.css" media="screen,projection" /> ?>
I also tried using the long php tags, but it still did not work.
<link rel="stylesheet" type="text/css" href=" <?php echo base_url()?> css/action.css" media="screen,projection" /> ?>

Base URL: $config['base_url'] = "http://localhost/";

action.css is currently in the following folders:

Any other suggestions?

Check in the Firebug Net tab or in your view source what the generated path is for the css file and report back Smile

Also, Your base path in the config file should include the folder name of where your site is located

And why is your css file in 4 different directories?

Thanks for your help stef. I am not longer getting the error after adding in: <?php $this->load->helper('url'); ?>

However, the CSS is still not loading. The base URL is still
http://localhost/ - does this need to be updated?

<?php $this->load->helper('url'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url()?>css/action.css" media="screen,projection" />

$config['base_url'] = 'http://localhost/directory your ci app is in/'


$config['base_url'] = "http://localhost/";

CSS file is located at "system/application/css"

The CSS file loads at "http://localhost/" with this line in the view file:
<link rel="stylesheet" type="text/css" href="system/application/css/action.css" media="screen,projection" />

However, the CSS file DOES NOT load at this page: http://localhost/index.php/action

The application file (action.php) is located at application/controllers and the view is in application/views.

Any other suggestions?

for that you can use your css like this also

echo link_tag(APPPATH.'css/mystyles.css');

APPPATH is defined path till you application folder.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.