#native_company# #native_desc#
#native_cta#

PHP enabled stylesheets Page 7

By Bertrand Potier
on November 24, 2002

The Real Fun!

Code Generation
This is the most obvious use of PHP inside a CSS stylesheet but not the one
with the highest added value. One example is the creation of repetitive style
definitions like for the HTML headings, in/decreasing the font size
automatically from the font size set in the visual configuration file:

<?php

for ($i=1$i<6$i++) {

 print( 
'H'.$i.' { ');

 print(
'font-size: '.($VISUALS[$SkinID]['page']['fontsize']+(6-$i)));

 print(
$VISUALS[$SkinID]['page']['fontunit'].';');

 print(
'font-weight: bold;');

 print (
' }');

}

?>



The main advantage is for the lazy ones, not having to type the same thing
over and over again. More seriously, this can automate the creation of style
definitions in various situations and I’ll give more examples if requested.

Browser/Platform Based Behaviors

Usually, Javascript is being used in the index file of the web site in order
to detect the browser/platform and load a different stylesheet. It happens that
the difference between this and this browser/platform specific stylesheet are
not so big and being able to adapt a unique stylesheet would ease everything
(let’s avoid duplication). For example, font size (again) can be a problem
depending on the Operating System (OS) of your visitor. Even at the same
resolution as on your WINDOWS OS, the text will appear to be smaller on Linux
and Mac OS platforms. I don’t have the chance to own a MAC OS so the value
tested may not be fully correct (extracted from index.php):

<script type="text/javascript" charset="ISO-8859-1">
 var browser = navigator.appName.toLowerCase();
 var platform = navigator.platform.toLowerCase();
 var detect = ; if ( platform.indexOf("mac") != -1 && detect) {
  location.replace("index.php?detect=false&browser=msie6");
 } 
</script>

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|