Katherine
Katherine

Reputation: 573

CodeIgniter - Linking an exernal css not working

Here is the hierarchy of my files

Codeigniter/
   applications/
       assets/
           styles.css
       ...
       views/
           welcome.php

   system/
       ...

under my style.css is this code

p {
    color: #3333ff;
    background-color: #66ff66;
}

and under the welcome.php is this one.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test</title>

    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/styles.css" />
</head>
<body>
     <p>test</p>
</body>
</html>

I set my base_url as

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

I cant understand why the css file isn't working

I also tried to change link to

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

but didn't work also

Upvotes: 0

Views: 7068

Answers (3)

Saqib Omer
Saqib Omer

Reputation: 5477

You have to define url in you constant.php paste following code in public_html_local/application/config/constants.php

define('URL','http://YOUR-HOST/APPLICATION-FOLDER/');

define('CSS',URL.'assets/css/');//make a new folder named as assets if you want css sources

now simply use following to use stylesheet.

<link rel="stylesheet" href="<?php echo(CSS.'simplereflect.css'); ?>">

Upvotes: 0

MJ X
MJ X

Reputation: 9054

1-If you are not using .htaccess and you did not removed your index.php file than put index.php inside the path to you css file.

2-If you used .htaccess and removed your index.php than put your css folder name inside your .htaccess file that way it should be accessable. and my links are working fine here is and example:

<link rel="stylesheet" href="<?=base_url()?>bootstrap/css/bootstrap.min.css" />

Upvotes: 3

Marc Audet
Marc Audet

Reputation: 46785

I have a similar local setup (XAMPP) and I have the the following file hierarchy:

public_html_local/
   applications/

   assets/
      css/
          styles.css
          ...
      js/
          jquery.js
          ...
      images/
          banner.jpg
          ...

   system/
       ...

In my config file:

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

and in my pages, I access my CSS files as follows:

<base href="<?php echo base_url(); ?>">
<link href="assets/css/reset.css" rel="stylesheet">
<link href="assets/css/styles.css" rel="stylesheet">

For me, I found it easier to keep my CSS files outside of the application folder.

In your case, you might expect the path to your CSS files to be:

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

However, if you try to access the CSS file from your local server using that URI, it probably won't work unless you changed the .htaccess file.

Upvotes: 5

Related Questions