#native_company# #native_desc#
#native_cta#

PHP enabled stylesheets Page 5

By Bertrand Potier
on November 24, 2002

The CSS Stylesheet File

The PHP enabled stylesheet is nothing more that a CSS stylesheet with some
PHP code in it. What is more interesting is the benefits of that association as,
purely from a coding point of view, there’s no complexity at all.
As for the visuals.inc file, the first steps are making sure
that any variables passed on to the stylesheet.css.php are properly
retrieved. This is where we’ll encounter one of the first benefits of including
PHP code in stylesheet: implement browser based behaviors without having to
create multiple stylesheets. This will be discussed with more details in the
next sections.
To be able to use the visual parameters defined in the
visuals.inc file, this file must be included in the PHP enabled
stylesheet. This is done using the require() function, as without
this file, the stylesheet would not behave properly. Now can start the real fun
of putting some PHP in CSS (I assume you know the basics about CSS). I won’t
explain anything here; see the next sections to understand the why.

<?php

 
if (substr(phpversion(),0,3) != '4.1') { 

  
$_REQUEST array_merge($HTTP_POST_VARS$HTTP_GET_VARS); 

 }

 if ( isset(
$_REQUEST['browser']) ) { 

  
$browser $_REQUEST['browser']; 

 } else if ( !isset(
$browser) ) { 

  
$browser  'ie5';    // 94% of the browsers on the web

 
}

 require_once(
'visuals.inc');

?>



body, h1, h2, h3, h4, h5, h6, p { 

 font-family: <?php print($VISUALS[$SkinID]['page']['font']); ?>

 font-size: <?php 

  
print($VISUALS[$SkinID]['page']['fontsize']);

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

 
?>;

}

body {<?php

 
print('background-color: '.$VISUALS[$SkinID]['page']['background']['color'].';');

?>}

<?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 (
' }');

 }

?>



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