BlackFire27
BlackFire27

Reputation: 1550

codeigniter and adding stylesheets

I add a stylesheet to codeigniter:

<head>
<meta charset="utf-8">
<title>Site Administrator</title>
    <link rel="stylesheet" href="../../css/administrator.css" type="text/css" ></link>

</head>

But the rules arent added. I go two directories up and go to the css.. The direction of the href is right.. I used the autocomplete feature in netbeans.. But why no rules are added to the page? is it codeigniters problem?

My rules in the stylesheet:

        #container
        {
           margin: 0px auto;
           width:50%;
           background-color: #99BC99;
        }

        #container:first-child
        {
           text-align: center;
        }

        #heading
        {

            text-align: right;

        }
        h2
        {
            float:right;
            margin-right: 130px;
        }
        a
        {
            text-decoration: none;
        }

My html:

<div id="container">
<h1>ממשק מנהל</h1>
<div id="heading">

      <h2>  
        <?php echo anchor('news/local/123', 'צור נושא', 'title="News title"'); ?>
            </h2>
        <h2>  
            <?php echo anchor('news/local/123', 'הוסף אמייל', 'title="News title"'); ?>
        </h2>
        <h2>  
            <?php echo anchor('news/local/123', 'שנה שם וסיסמה', 'title="News title"'); ?>
        </h2>

</div>

UPDATE:

This is what it gives me:

This is what it gives me:  <link rel="stylesheet" href="http://localhost/finance_site/index.php/css/administrator.css" />

Whenever, I do this:

  <link rel="stylesheet" href="<?=site_url('css/administrator.css');?>" /> 

Alright, I got it, it is like this:

   <link rel="stylesheet" href="http://localhost/finance_site/css/administrator.css" /> 

Is there a way to re-write it so it will be a relative link to code igniter...or at least more portable?

Upvotes: 2

Views: 4016

Answers (4)

Philip
Philip

Reputation: 4592

CSS - use the base tag, this sets a default target for all links

<base href="<?php echo base_url();?>" />

-

<link rel="stylesheet" href="assets/css/some_file.css" />

JS - To pass the base_url to javascript if you need to make ajax requests you could use this before you include your external javascript files(s)

<script>
var BASE_URL = "<?php echo base_url();?>";
</script>

Upvotes: 0

James Arnold
James Arnold

Reputation: 980

I tend to place things such as stylesheets, css, js, etc in /public.

You can then use <?=site_url('public/css/administrator.css);?> in the view.

Upvotes: 2

Shomz
Shomz

Reputation: 37701

Try using /css/administrator.css or css/administrator.css.

Upvotes: 0

dotoree
dotoree

Reputation: 2993

use href="<?php echo base_url();?>css/administrator.css

Upvotes: 3

Related Questions