|
Posted by Michael Trausch on 10/01/01 11:36
Curtis wrote:
[snip]
>
> 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.)
>
> 2. If not, is it theoretically possible to generate CSS
> sheets with PHP, which would allow the declaration and use
> of constants and functions?
>
I do not know about CSS permitting variables and the like, however,
there are predefined constants for colors. If you want to define your
own, or create a dynamic style sheet, you can do that with PHP.
For example:
-----
<?php
header("Content-type: text/css");
define(BLUE, '00f');
?>
body
{
background-color: <?php echo BLUE; ?>;
}
-----
Since PHP runs on the server-side you can do this. However, you would
call it from XHTML by doing this instead:
<link type="text/css" href="cssfile.php" rel="stylesheet" />
You can also do this to have multiple types of CSS in one style sheet,
e.g., for print vs. display, though there are some (questionably
supported) mechanisms in place for doing that already. The only way
that I've found that works in every browser that I've tested is to call
the style sheet twice from the XHTML, or to have to different style
sheets. If you want to use PHP to make the difference, you can do so by
doing something like:
<link rel="stylesheet" media="screen" type="text/css"
href="css.php?media=screen" />
<link rel="stylesheet" media="print" type="text/css"
href="css.php?media=print" />
And in the css.php file, check the value of $_GET['media'] using if
statements or switch/case. You can also work with browser detection in
the CSS script so that you can work around quirks in various browsers,
most notably, MSIE and it's lack for standard CSS support. Note that
the more you use the PHP in the CSS code, the more complex it gets and
the harder it may be to work with it properly. You could, however,
create an OO solution to this problem by using a PHP class to create
valid CSS, but that's another story altogether, and there may even be
such a thing that exists, but if there is, I don't (yet) know about it...
HTH,
Mike
Navigation:
[Reply to this message]
|