English 中文(简体)
Global variables in css style sheets
原标题:

I hava an absolute url in my stylesheet. http://localhost/images/myimage.jpg.

I also have a config class with the following constant

const SITE_ROOT =  http://localhost/images 

On php pages i write config::SITE_ROOT . "/myimage.jpg" so when i move the site to the production server i can change the site root in one central location.

Is there any way to do this in my style sheet without putting it in the page? Relative url s are not an option because i am using mod rewrites and relative url s don t work.

最佳回答

You can write your SITE_ROOT constant into the CSS files by parsing them with PHP. Add this to .htaccess:

AddHandler application/x-httpd-php .css

Then embed PHP into the CSS files as you would do in any .php file.

问题回答

There is no way to do this with CSS. If you want to do something like this you could make it a PHP file and use variables that way.

But couldn t you just use absolute URLs?

background-image: url(/images/myimage.jpg);

Will work on any server, is not relative, and will find the files from the root.





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签