Jump to content

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!
Link to comment
https://forums.phpfreaks.com/topic/10357-using-php-in-external-css-file/
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.
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!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.