Thursday, November 4, 2010

Using PHP to manage CSS variables

style.php:


<?php
/*** set the content type header ***/
header("Content-type: text/css");

/** set the paragraph color ***/
$para_color = red;

/*** set the heading size ***/
$heading_size = '5em';

/*** set the heading color ***/
$heading_color = blue;
?>

p{
        color: <?php echo $para_color;  ?>;
        font-weight: bold;
        font-size: 1.2em;
        text-align: left;
}

h1{
        color: <?php echo $heading_color; ?>;
        font-size = <?php echo $heading_size; ?>;
        text-align: centre;
}

div.logoContainer {
  background-color: green;
  color:  <?php echo $para_color;  ?>;
 }


main.html:
<html>
<head>
<title>foo</title>
<link rel="stylesheet" href="style.php" media="screen">
</head>
<body>
<h1 >CSS Variables</h1>
<p>
This is some Text
</p>
<div class="logoContainer">
LogoContainer color
</div>

</body>
</html>
Output Display:

CSS Variables

This is some Text 
LogoContainer color

No comments:

Post a Comment