Forum Moderators: coopster

Message Too Old, No Replies

Stumped. Importing StyleSheet using Switch/Case

What is the correct syntax?

         

Storyman

5:31 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



I'm using a simple radio group buttons to let the user select the stylesheet they want.

Then the switch/case script imports the desired stylesheet.

What is wrong with this script (because it doesn't work)?

Okay I know it is the "@import/blue.css"; but I can't figure out what it should be. Is there a site that explains how to do it?

case "blue":
echo "@import/blue.css";
break;

coopster

6:09 pm on Aug 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Seems to me you are missing a space there.
"@import blue.css"

Warboss Alex

6:45 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



Which should actually be

"@import \"/blue.css\""

If you want to be valid xhtml, of course..

Storyman

10:08 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



Thanks guys for the help. What I found was that the <style> tag has to be included and this is what I came up with:

echo "<style media=\"screen\" type=\"text/css\">
@import blue.css;
</style>";

The PROBLEM now is that when the blue (or any other color) stylesheet is selected only the portion that has content will will turn blue. Everything below the contentt will remain unchanged UNLESS the same color is selected again. If a color is selected twice, then the entire screen will turn the selected color. (Maybe I should mention that the CSS stylesheets have only the background attributed selected for the body.)

In other words if there is content halfway down the page the background will turn the selected halfway down the page, but if the same color is selected a second time the entire screen will be the selected color.

What needs to be done to get the entire screen to fill with the correct color the first time out?

Warboss Alex

4:38 am on Aug 17, 2004 (gmt 0)

10+ Year Member



I think that's more of a CSS issue than a PHP one.

How about posting the CSS for us? And maybe some sample html?

It sounds to me as if you're importing the stylesheet in the wrong place. It should be placed in the <head></head> element. When the stylesheet is selected, what happens? Is the page loaded again or is the <style> tag printed into the page?

Storyman

5:31 pm on Aug 17, 2004 (gmt 0)

10+ Year Member



Warboss Alex,

After posting I realized that this is more of a CSS problem than PHP, but initially wasn't sure of it.

What I've come up with I realize isn't correct and for some reason it is the only way I can get it do what I need it to do.

case "blue":
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"blue.css\">
<style type=\"text/css\">
@ import url(blue.css);
</style>";
break;

I've tried moving the first line 'link rel' to the <head> tag and left the 'style' section inside the case. It loads the stylesheet up initially, but on subsequent calls it fails to reload.

Now I'm not so sure if it is a CSS problem or PHP or both because it does work with Javascript when the 'link rel in is the head section--just not PHP.

Warboss Alex

9:16 am on Aug 18, 2004 (gmt 0)

10+ Year Member



Hard-code a stylesheet into the page, then see if it comes back on subsequent calls. If so, the PHP script's not submitting it. Are you sure there's some default value for the PHP-generated stylesheet? A user isn't expected to load the sheet every page.. does the script 'remember'?