AddType application/x-httpd-php .css
A html file may also include a PHP file, in the same manner as it includes a CSS file. This means the stylesheet can be renamed from style.css to style.php. When included from within the head of the HTML document, the link will look like this.
<link rel="stylesheet" href="style.php" media="screen">
With the link to the style.php file in place, the PHP within the stylesheet is just a normal PHP file.
<?php
/*** set the content type header ***/
header("Content-type: text/css");
/** set the paragraph color ***/
$para_color = '#0000ff';
/*** set the heading size ***/
$heading_size = '2em';
/*** set the heading color ***/
$heading_color = '#c0c0c0';
?>
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;
}
The code above will produce a Cascading Style Sheet as follows:
p{ color: #0000ff; font-weight: bold; font-size: 1.2em; text-align: left; } h1{ color: #c0c0c0; font-size = 2em; text-align: centre; }
<html>
<head>
<title>foo</title>
<style type="text/css">
@variables {
LogoBGColor: #e0e0e0;
}
div.logoContainer {
background-color: var(LogoBGColor);
color: red;
}
</style>
</head>
<body>
<h1 class="heading">CSS Variables</h1>
<div class="logoContainer">
This is some Text
</div>
</body>
</html>
No comments:
Post a Comment