PDA

View Full Version : PHP in CSS


Rikki Tikki Tavi
March 13th, 2006, 03:31 AM
This is probably a n00bish question but anyways; is their anyway to imbed php code in a .css file without having to rename the extension and leaving as a .css extension.

Innocence
March 13th, 2006, 06:42 AM
Just a question, why do you need to do that? You can't without changing the extention, but there may be a workaround depending on what you wanna do.

pokejungle
March 14th, 2006, 11:45 PM
I do not believe there's anyway to put PHP into a CSS file.

You can always just put the code into your <head> of the actual page though~

PD Wooper
March 16th, 2006, 10:24 PM
Hmm...I'm not at all sure about this but...
in your .htaccess file (create if you have none) add this line

AddType application/x-httpd-php .css

AFAIK it will still be treated as a css file..

Or alternatively, change the link to style.php and do it in there.

Dragonfree
March 16th, 2006, 10:40 PM
Why exactly would you want PHP code in a .css file?

Koroku
March 18th, 2006, 07:33 PM
If you include it into a php file, and don't use it just... alone, just use the normal php code.

Shining Arcanine
March 18th, 2006, 08:01 PM
PD Wooper is right. That is how you would do it if your web host is using an Apache server and allows use of .htaccess.

Geometric-sama
March 19th, 2006, 01:51 PM
I assume you'd want to do something like if (condition) { this css } else { other css }?

Just use a php file for it. Put the CSS in <style type="text/css"> tags, and include() the php file into your page.

Bowsa
March 27th, 2006, 12:58 AM
well you could google it because i found a website that does all that but i frogot it XD

pokejungle
March 27th, 2006, 02:18 AM
Why exactly would you want PHP code in a .css file?
There are a lot of uses for it~ For example, you can change elements depending on what browser a visitor is using.

Or let them change the CSS using certain coding.

Dragonfree
March 27th, 2006, 06:27 PM
There are a lot of uses for it~ For example, you can change elements depending on what browser a visitor is using.

Or let them change the CSS using certain coding.
Eww, browser detect. :x

If you want to change stylesheets or something like that, you can just include different stylesheets depending on a variable...

Geometric-sama
March 28th, 2006, 05:28 AM
If you're letting the user change CSS then it's more likely to be Javascript than PHP, since JS is a CSSL and has features that allow you to change CSS on the fly, while PHP is a SSSL and you'd need to rebuild the entire CSS each time.

Koroku
March 28th, 2006, 05:44 AM
Or he's lazy and wanted to do like

<?
// Declare variables
$text = "515C89";
$link = "263059";
$background = "B7BDD6";
$border = "D3D7E6";
?>
<style type="text/css">
<!--
<? print "
a { color: #$link; text-decoration: none; }
a:link { color: #$link; text-decoration: none; }
a:visited { color: #$link; text-decoration: none; }
a:active { color: #$link; text-decoration: none; }
a:hover { color: #$link; text-decoration: none; }
table { color: #$text; font-family: Tahoma; font-size: 10pt; background-color: #$background; }
body { color: #$text; font-family: Tahoma; font-size: 10pt; background-color: #$background; }
textarea { border: 1pt solid #$link; color: #$text; font-family: Tahoma; font-size: 9pt; background-color: #$background; }
.big { color: #$text; font-family: Tahoma; font-size: 14pt; }
.strike { color: #$text; font-family: Tahoma; font-size: 10pt; text-decoration: line-through; }
.center { text-align: center; }
.left { text-align: left; }
"; ?>
-->
</style>(copied from JKN)

Geometric-sama
March 28th, 2006, 05:58 AM
Which is what I said, just <style type="text/css"> and include().