|
Posted by NC on 10/28/06 16:35
IchBin wrote:
>
> How do you typically integrate CSS into a PHP script.
> Do you embed it or reference a external CSS file?
Either or both; just like in HTML. Additionally, PHP allows you
to generate CSS dynamically.
Let's say your HTML/PHP/whatever files have this tag:
<LINK rel="stylesheet" href="style.php" type="text/css">
Then, inside stytle.php, you may write, for example:
header('Content-Type: text/css');
switch ($_GET['palette']) {
case 'blueandyellow':
$b = '#0000ff';
$c = '#ffff00';
break;
case 'greenandsilver':
$b = 'green';
$c = 'silver';
break;
default:
$b = '#ffffff';
$c = '#000000';
}
echo <<<EOCSS
body {
color: $c;
backrgound-color: $b;
}
<!-- Many other styles go here -->
EOCSS;
Then, you can switch the color palette (or any other attributes
derfined
by the stylesheet) is as easy as going from
<LINK rel="stylesheet" href="style.php?palette=blueandyellow"
type="text/css">
to
<LINK rel="stylesheet" href="style.php?palette=greenandsilver"
type="text/css">
The standard recommendation is to put as much style information
into an external stylesheet as possible and suggest that the clients
cache the stylesheet. This way, the stylesheet gets requested only
once.
> Also, any tips and Preferred Resources?
The CSS Specificatoin is your friend:
http://www.w3.org/TR/CSS2/
Cheers,
NC
Navigation:
[Reply to this message]
|