0

I am setting up a local CodeIgniter development environment on my windows machine using xampp. I am having a little bit of trouble with the css files. I am guessing that I need to configure my application's path somewhere.

The development url is this (this is routed to the home page ):

localhost/my_app

I am linking my stylesheet like this

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

on a production server this works just fine, but the css will not load locally because it seems to be linking to localhost/css/style.css instead of localhost/my_app/css/style.css.

when I change the link to this, it works:

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

this link works, but still will not load the background-image:url('/images/image.png') I am using.

I don't want to code all of my paths with my_app/directory_i_want_to_access because then I will have to go back and change them whenever I push to production.

Spencer Cooley
  • 8,471
  • 16
  • 48
  • 63

2 Answers2

2

Try:

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

For image links within CSS, say this is your folder structure

/ Assets
| - /images
| - | - image.png
| - /css
| - | - / style.css

Just link to the images relative to the CSS file, so in this case, it'll be ../images/image.png

Indranil
  • 2,451
  • 1
  • 23
  • 31
  • That works great thanks. I still have a problem with the background-image:url(/images/image.png) though. I don't think I can write php into a css file. – Spencer Cooley Dec 17 '11 at 22:28
  • No, for images within the CSS file, they only check the path relative to the css file. So, just put it in the same place, and use `(../images/image.png)` if your CSS file is in the CSS folder and images in images folder inside the same assets folder – Indranil Dec 17 '11 at 22:31
0
<base href="<?php echo base_url(); ?>">

add that you your html file, your links should work now.

courtesy of phil sturgeon

Philip
  • 4,592
  • 2
  • 20
  • 28