PHP variables inside external CSS
There’s a way of using php variables inside your css external file.
First, you have to rename your css file to “mycssfile.php”.
Then, insert the following line of code on top of the file:
Finally, don’t forget that the reference to the css file in your HTML is “mycssfile.php”.
Inside “mycssfile.php” you can define variables like colors, typography, measures, etc…
-
-
<?php
-
$color1 = "#CCCCCC";
-
$color2 = "#FFFFFF";
-
$type1 = "Helvetica";
-
etc…
-
?>
-
Then, use them with a normal echo statement:
-
-
h1 {
-
color: <?php echo $color1 ?>;
-
font-family: <?php echo $type1 ?>;
-
}
-






