CodeIgniter Forums
Background image in CSS - How to use base_url() in a CSS file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Background image in CSS - How to use base_url() in a CSS file (/showthread.php?tid=28244)



Background image in CSS - How to use base_url() in a CSS file - El Forum - 03-05-2010

[eluser]Juan Velandia[/eluser]
Hello, again a newbie question.

I'd like to know how can I use the base_url() whitin a CSS file? is this possible? or if I want to use a CSS style with a background I should do something like this?:

body{
padding:0px;
margin:0 auto;
background: url(http://example.com/system/application/views/images/background.jpg) 0 0 repeat-x;
}

Thanks a lot

Juan


Background image in CSS - How to use base_url() in a CSS file - El Forum - 03-05-2010

[eluser]danmontgomery[/eluser]
You should have an images folder in your css folder. All images in CSS are relative to the CSS file, so in that case you could always just use:

Code:
background: url(images/background.jpg) 0 0 repeat-x;



Background image in CSS - How to use base_url() in a CSS file - El Forum - 03-05-2010

[eluser]Juan Velandia[/eluser]
Thanks noctrum, you are right, It will surelly work!

Juan


Background image in CSS - How to use base_url() in a CSS file - El Forum - 03-05-2010

[eluser]InsiteFX[/eluser]
Here is another way of doing...

Code:
<?php
    header('Content-type: text/css');
    $img_url = base_url();
?>

.ie6hack {position:absolute; top:0px;}

* html img.logo {
    background:none;
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='<?php echo $img_url;?>/logo.png', sizingMethod='crop');
}

Name yourname.php


Enjoy
InsiteFX


Background image in CSS - How to use base_url() in a CSS file - El Forum - 03-05-2010

[eluser]Juan Velandia[/eluser]
thanks insiteFx, i´ll check it, but i have to recognize that´s a bit confusing to me...


Background image in CSS - How to use base_url() in a CSS file - El Forum - 03-05-2010

[eluser]InsiteFX[/eluser]
Hi,

it sets the header to a css file but it is a php file with css code in it.
This is a php file that has all the css in it just make it and include it.

The ccs code is just part of my ie6 hacks.

Enjoy
InsiteFX