|
Posted by NC on 10/13/22 11:36
Curtis wrote:
>
> CSS: Any way to use variables or constants?
Any way you want...
> So, as in PHP, we might declare a global
>
> $master_color = thevalue;
Or even do something like this:
if (isset($_GET['master_color'])) {
$master_color = $_GET['master_color'];
} else {
$master_color = '000000';
}
> The upshot is, one could do a blue-themed template and
> change it to (say) a gray or burnt-orange or purple by
> simply changing a couple of constants.
Or by passing a master color in a GET variable, as shown above...
> This raises two questions:
>
> 1. Are there existing CSS techniques whch would allow
> something like this, at least in part? (I'm aware of some
> ability to use percentages for some aspects of certain
> elements.)
This is entirely up to you. You generate CSS just as you would
generate HTML.
> 2. If not, is it theoretically possible to generate CSS
> sheets with PHP, which would allow the declaration and use
> of constants and functions?
It's not just theoretically possible; people do it all the time.
Consider this simple PHP script:
header('Content-type: text/css');
if (isset($_GET['text'])) {
$text = $_GET['text'];
} else {
$text = '000000';
}
echo <<<EOSS
body {
color:#$text;
}
EOSS;
Now let's say this script is stored in the file called style.php, and
various other scripts refer to it in different ways:
<LINK rel="stylesheet" href="style.php" type="text/css">
<LINK rel="stylesheet" href="style.php?text=808080" type="text/css">
<LINK rel="stylesheet" href="style.php?text=0956A6" type="text/css">
The result is a dynamically generated style sheet partiallly controlled
by the document being geherated...
Cheers,
NC
Navigation:
[Reply to this message]
|