0

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

5
  • Are you testing this on a live, publicly available website, or locally? Commented Jun 29, 2013 at 21:49
  • i test it locally.... Commented Jun 29, 2013 at 21:51
  • Can you paste code that comes to browser? (page source) Sometimes debugging tools built in browser may help (I mean Dragonfly in Opera, Firebug in Firefox or Dev Tools in Chrome). Commented Jun 29, 2013 at 22:18
  • You forgot the 's' in applications. Commented Jun 30, 2013 at 0:41
  • 1
    This may clear WHY? stackoverflow.com/questions/11128740/… Commented Jun 30, 2013 at 8:53

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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" />

Comments

0

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'); ?>">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.