Jump to content

Archived

This topic is now archived and is closed to further replies.

benjudy

Using php in external css file

Recommended Posts

I have been wondering if it is possible or legal to use php (conditionals, for example) in an external .css file.

I've been experimenting, but so far it doesn't seem to work.

If it does work, can someone post a simple example?

If it's not allowed, can someone link to a web page explaining why not?

I'd appreciate links to any resources about this. I've been looking around the web but haven't found an answer.

Thanks!

Share this post


Link to post
Share on other sites
not sure i understand [i]why[/i] you need to do this? your css file will be imported to the (example) index page already, and from there, you can manipulate it from there, can't you?

but anyways, if you can set your server to process a .css file extension as php and it should work.

Share this post


Link to post
Share on other sites
Actually save your css file with a php file extension now make sure you put the following code as the very firstline in your css file:
[code]<?php header("Content-type: text/css"); ?>
/*rest of css here*/[/code]
Now you can use PHP code in your style sheet but the stylesheet must be saved with a php file extension and not a css file extension!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.