
Huh? Yes of course classes and ID's... Despite my prolixity I may have failed to properly explain myself: the whole point is that the css for id or class
itself might need to be different...
Maybe this one tiny example will clarify one of the scenarios/reasons. Naturally the parameters would be put into a config file or somewhere in a database. You can also use http post and get or even cookies if you want the user to be able to choose/keep his favorite layout..
<?php
$pagewidth = 800;
$sidewidth = 200;
$mainalign = 'left';
$css = array();
if ($mainalign == 'left') {
$other = 'right';
} else {
$mainalign = 'right'; // typos revert to 'right'
$other = 'left';
}
if loaded(side) {
$css[] = '#main {float:' . $mainalign . ';width:' . ($pagewidth-$sidewidth) . 'px;}';
$css[] = '#side {float:' . $other . ';width:' . $sidewidth . 'px;}';
} else {
$css[] = '#main {width:' . $pagewidth . 'px;}';
}
foreach ($css as $line) { echo $line; }
?>
loaded(side):
as y'all 'll understand: this (CMS) function checks whether the side thingie is loadedSo how would I put a feature like this in external stylesheets? Can I use php in .css files? Or can I link to a stylesheet named mysheet.php (or for that matter, perl, cgi, asp whatever)
In my limited knowledge and experience I have assumed the <head> section in a webpage would be the most logical place for something like this.. just enclose the whole thing in <style> and </style>.
Let's say you put it into mycss.php and do an include somewhere in the webpages' head section, a foreach ($css as $line) { echo $line; } would still generate the css
and put it in the head anyway..
I can also
not write to a css file on the server and then link to that.. the next client might view a different page, where different thingies are loaded and therefore requiring different css
Alternatively, I could do these calculations in the body section, simply echoing different html such as
<body>
<?php if loaded(side) {
echo '<div id="main-' . $mainalign . '">';
/* do your content here */
echo '</div>';
echo '<div id="side-' . $other . '">';
/* do your side thingie here */
echo '</div>';
} else {
echo '<div id="main">';
/* do your content here */
echo '</div>';
};?>
</body>
Calculating it within the body, writing to divs instead of to css would be fine if it were just the few parameters and just the two divs as in this example... but it tends to grow very complex if you have a magnitude of parameters.
Any thoughts on this ??
Post edited Tuesday, 18. November 2008, 08:23:24