Topic: passing variables to external css? (Page 1 of 1) |
|
---|---|
Maniac (V) Inmate From: there...no..there..... |
posted 01-11-2007 22:19
Here is what I am trying to do. I have pages that are loaded from a php include. I need to pass variables to an external style sheet as well. It can be a lot of variables depending on the page. code: switch ($_GET['link']){ case 'page1': $page = "pages/page1.php"; $bodyClass="page1"; $bgColor = "#008000"; break; case 'page2': $page = "pages/page2.php"; $bodyClass="page2"; $bgColor = "#800000"; break; default : $page = "pages/main.php"; $bodyClass = "main"; $bgColor= "#8080FF"; }
code: <? header("Content-type: text/css"); ?> body { background:<?=$_GET['bgColor'];?>; }
code: <div> <a href="index.php?link=page1">Page 1</a><br /> <a href="index.php?link=page2">Page 1</a><br /> <a href="index.php?link=main">Main</a> </div>
code: <a href="index.php?link=page1&bgColor=#800000">Page 1</a><br />
|
Paranoid (IV) Inmate From: Norway |
posted 01-11-2007 22:37
make sure to pass the parameters in GET to the external stylesheet, i.e: code: <!--here be doctype declaration, head, ... --> <link type='stylesheet' media='screen,printer' href='style.php?link=<? echo $_GET['link']; ?>' /> <!-- here be monsters, script tags, the body and all the malarkey --> Hope that helps |
Lunatic (VI) Inmate From: under the bed |
posted 01-11-2007 23:45
I think you may be overcomplicating the issue. Is the <body> the only element to be affected? code: body.page1 h1 { ...styles... }
|
Paranoid (IV) Inmate From: Norway |
posted 01-11-2007 23:52
DL-44: sure, that's the cascading is one of the biggest strength of CSS. Add to that that having a single biiiig stylesheet that can be cached beats having a zillion of smaller not so cachable ( due to the arguments passed in GET ) stylesheets any time. |
Maniac (V) Inmate From: there...no..there..... |
posted 01-12-2007 00:42
DL-44: The body class is just one that would be affected. There are a bunch more depending on the page. The "About Us" page might have 5 - 6 elements that would be different than the rest, the "Contact Us" page would have maybe 10 (just guessing on the numbers). That is why I just wanted to pass variables to the style sheet. code: body{ margin:0px; padding:0px; }
code: body.page1{ background-color:#8080FF; }
|
Paranoid (IV) Inmate From: Norway |
posted 01-12-2007 00:51 |
Lunatic (VI) Inmate From: under the bed |
posted 01-12-2007 02:03
Anything specified in the secondary stylesheet will overide the same specs in the primary. |
Maniac (V) Inmate From: there...no..there..... |
posted 01-12-2007 04:08
quote:
|
Bipolar (III) Inmate From: midair |
posted 01-14-2007 02:02
quote:
|
Lunatic (VI) Inmate From: under the bed |
posted 01-14-2007 02:47
what you need to look at is mod_rewrite |
Bipolar (III) Inmate From: midair |
posted 01-17-2007 15:25
Thanks DL-44 |
Maniac (V) Inmate From: there...no..there..... |
posted 01-18-2007 02:01
quote:
|
Bipolar (III) Inmate From: midair |
posted 01-18-2007 14:32
Thanks CPrompt |
Nervous Wreck (II) Inmate From: |
posted 04-10-2016 20:31
long sought this information, thank you guys! |
Maniac (V) Inmate From: The Pool Of Life |
posted 04-11-2016 12:07 |
Maniac (V) Mad Librarian From: Seoul, Korea |
posted 04-22-2016 07:29
Now that's some prime necroposting there, that is. |