1

Topic: CSS + PHP for easy COLORS changing ...

I'm working on many xhtml sites and the code color is quite the same ...

for menu, a color, but this same color is used for a title, or a link, for example ...


I would like to know how to do with php ....

<?
$color1 = "#FF6600";
$color2 = "#FFF";
$color3 = "#EEE";
?> 


in css ... I would like to do ...


p {
  font-size : 12px;
  color : $color1;
}



but ... how declare php in css ?!! rename the css file in php ?!

Re: CSS + PHP for easy COLORS changing ...

you could make 3 different css files and make a php script to get the css you need.

Re: CSS + PHP for easy COLORS changing ...

Rod wrote:

but ... how declare php in css ?!! rename the css file in php ?!

Yup. Or change the MIME type of .css files on your web server to the PHP MIME type, but I don't see any point in that.

4

Re: CSS + PHP for easy COLORS changing ...

The MIME type is the content type presented to the web user; if you did that, the MIME type returned would be that of PHP source code.

Try renaming the .css file .php, and putting this at the top of it:

<?php
header('Content-type: text/css');
?>

That should do the trick.

5

Re: CSS + PHP for easy COLORS changing ...

http://www.barelyfitz.com/projects/csscolor/
http://www.1976design.com/blog/archive/ … namic-css/

6 (edited by buzzkill 2005-02-21 21:21)

Re: CSS + PHP for easy COLORS changing ...

Rod,  I had to do something similar (I think) with alternating row colors.  I just created two CSS rules.

External CSS file has this...

.rowcolor1 {background-color: #F1F1F1;}
.rowcolor2 {background-cloro: #CCCCCC;}

Then I used PHP to do the work for me.

$rowcolor1 = "rowcolor1";
$rowcolor2 = "rowcolor2";

$row_count =0;

$query ....
while ($row = mysql_fetch_array($query)) {

  $row_color = ($row_count  % 2) ? $rowcolor1 : $rowcolor2;
  
  echo '<tr class="'.$row_color.'">';
  .....
  $row_count++;

}

Not really sure if this is what your trying to do with PHP and CSS.

Paul: is this how you achieved the colors for the post icons?  Or did you manually adjust the colors for each "corner"?

good stuff!

7

Re: CSS + PHP for easy COLORS changing ...

The icons have their colours set manually. It really wouldn't be worth the bother of doing it any other way.

The real advantage of using dynamic css comes in when you want to change styles based on some variable e.g. a different banner for each month, a different colour scheme for different seasons etc. Or where you have several sites on the same server which use common styles which can all be set with one php file. The downside is that css served as php might not be cached.

8

Re: CSS + PHP for easy COLORS changing ...

You can make it cached by sending Cache-Control: headers. See PHP documentation and RFC 2616.