PHPBuilder - PHP enabled stylesheets Page 7

RSS Twitter
Articles Html

PHP enabled stylesheets - Page 7

by: Bertrand Potier
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:

for ($i=1$i<6$i++) {
'H'.$i.' { ');
'font-size: '.($VISUALS[$SkinID]['page']['fontsize']+(6-$i)));
'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) {

« Previous Page
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Bertrand Potier



(Maximum characters: 1200). You have characters left.