benjudy Posted May 24, 2006 Share Posted May 24, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/10357-using-php-in-external-css-file/ Share on other sites More sharing options...
.josh Posted May 24, 2006 Share Posted May 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10357-using-php-in-external-css-file/#findComment-38638 Share on other sites More sharing options...
wildteen88 Posted May 24, 2006 Share Posted May 24, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/10357-using-php-in-external-css-file/#findComment-38643 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.