Welcome Guest, Not a member yet? Register   Sign In
css images not loading
#1

[eluser]MV[/eluser]
Hi,

my CI project has a simple CSS which uses some background images in it for certain things. The problem is that, if i dont give them their full url, they simply wont load.

This CSS doesnt work:



body {
background:#fff url('images/back.png') no-repeat top left;
margin: 0px 0px;
padding: 0px;
text-align: left;
font: 11px Verdana, Helvetica, sans-serif;
}

This works:

body {
background:#fff url('http://localhost/ci_project/images/back.png') no-repeat top left;
...


The CSS loads perfectly, and i use base_url() to do so, but inside the CSS i dont have a clue as to how i can make images work.

Thanks.
#2

[eluser]MV[/eluser]
Looked everywhere for a solution to this, even on this forum, but it seems i didnt search with the correct terms. Also, the solution isnt very visible because its stupid simple, and i really should know. :-P

Images inside the CSS are relative to the path of the CSS file, not the page. In my case, this works:

background:#fff url('../images/back.png') no-repeat top left;

(note the two dots)

This works because my CSS file is inside a dir called "css" on the base url. My "images" dir is at the same level of the "css" dir. :-P




Theme © iAndrew 2016 - Forum software by © MyBB