Stylesheet question

  • Thread starter Samuël van Laere
  • Start date
S

Samuël van Laere

Currently i offer 4 stylesheets,
the user can use the php based style switcher to select a different
stylesheet. (code was found on this group :))

Do i also need to link the stylesheets in the html as alternate stylesheet?

Or isn't there any need, since i allready offer a way of picking a different
stylesheet?
 
F

Fabian Neumann

Am 02.11.2003 14:15 schrieb Samuël van Laere:
Do i also need to link the stylesheets in the html as alternate stylesheet?

Or isn't there any need, since i allready offer a way of picking a different
stylesheet?
There is no need for that in technical sense. But Mozilla(Firebird)
users will be happier, since their browsers offer to change style sheets
based on the <link>-tag in your HTML code, without having to use your
PHP script.

So if you can offer it, do it.

Fabian
 
L

Lauri Raittila

In said:
Currently i offer 4 stylesheets,
the user can use the php based style switcher to select a different
stylesheet. (code was found on this group :))
OK.

Do i also need to link the stylesheets in the html as alternate stylesheet?

It wouldn't do much harm.
Or isn't there any need, since i allready offer a way of picking a different
stylesheet?

Not with current implementions of browsers, on normal situations.

I don't think multible stylesheets for same media are usefull exept maybe
when there is some idiot boss somewhere that demands bells and whisles,
and only way to get reasonable style is to do it using alternate
stylesheet (and then look server logs in hope alternate stylesheet will
be used more than default).

Of course, there is exeptions.


Of course, if one aim is to learn how to make stylesheets, it doesn't
hurt to put them in use. But for webpage, it usually is more usefull to
add more content.
 
T

Toby A Inkster

Fabian said:
There is no need for that in technical sense. But Mozilla(Firebird)
users will be happier, since their browsers offer to change style sheets
based on the <link>-tag in your HTML code, without having to use your
PHP script.

Ditto regular Mozilla, ditto Opera, ditto Konqueror[1].

*However* a PHP style switcher is in many ways *better* than just relying
on rel="alternate stylesheet", as browsers don't[2] carry over the choice
of an alternate stylesheet when you go on to the next page :-(

Of course, *best* is to offer both. (Which I do)

[1] Konqueror 3 does funny things with alternate style sheets. When a list
of alternate stylesheets is given, it uses the first one by default! I
have yet to add a workaround to my site, although I do plan to do so[3].
Safari does not suffer from this bug. More details here:
http://bugs.kde.org/show_bug.cgi?id=54335

[2] Except Konqueror.

[3] I generally don't work around bugs in browsers, but the fix should be
pretty easy.
 
M

Michael Wilcox

Fabian Neumann said:
But Mozilla(Firebird)
users will be happier, since their browsers offer to change style
sheets based on the <link>-tag in your HTML code

What exactly is this code?
 
S

Samuël van Laere

Toby A Inkster said:
Fabian said:
There is no need for that in technical sense. But Mozilla(Firebird)
users will be happier, since their browsers offer to change style sheets
based on the <link>-tag in your HTML code, without having to use your
PHP script.

Ditto regular Mozilla, ditto Opera, ditto Konqueror[1].

*However* a PHP style switcher is in many ways *better* than just relying
on rel="alternate stylesheet", as browsers don't[2] carry over the choice
of an alternate stylesheet when you go on to the next page :-(

Of course, *best* is to offer both. (Which I do)

[1] Konqueror 3 does funny things with alternate style sheets. When a list
of alternate stylesheets is given, it uses the first one by default! I
have yet to add a workaround to my site, although I do plan to do so[3].
Safari does not suffer from this bug. More details here:
http://bugs.kde.org/show_bug.cgi?id=54335

[2] Except Konqueror.

[3] I generally don't work around bugs in browsers, but the fix should be
pretty easy.

Fabian and Toby,
thanks for the answers they are mosy usefull.
What kind of workaround could i use?
I wonder if i should bother anyhow, the next build/version is likely to
solve that isue right?
 
S

Samuël van Laere

Toby A Inkster said:
Fabian said:
There is no need for that in technical sense. But Mozilla(Firebird)
users will be happier, since their browsers offer to change style sheets
based on the <link>-tag in your HTML code, without having to use your
PHP script.

Ditto regular Mozilla, ditto Opera, ditto Konqueror[1].

*However* a PHP style switcher is in many ways *better* than just relying
on rel="alternate stylesheet", as browsers don't[2] carry over the choice
of an alternate stylesheet when you go on to the next page :-(

I'm using the script you wrote Toby (i think) it works great :)
 
D

David Graham

I'm using the script you wrote Toby (i think) it works great :)Any chance of making it available for me.

thanks
David
 
S

Samuël van Laere

David Graham said:
Any chance of making it available for me.

thanks
David

Hello David,

This is the code as it was published by Toby:
============================ example.php =============================
<!DOCTYPE whatever>
<?php
$s = $_GET['style'];
if (!($s)) { $s = 'red'; }
?>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" media="screen,projection"
<?php echo ' href="styles/' . $s . '.css"'; ?> >
</head>
<body>
<h1>Example</h1>
<p>The style you chose was <code><?php echo $s ?>.css</code>.</p>
<ul>
<li><a href="example.org?style=red">Red</a></li>
<li><a href="example.org?style=white">White</a></li>
<li><a href="example.org?style=black">Black</a></li>
</ul>
</body>
</html>
======================================================================


With regards,
Samuël van Laere
the Netherlands
http://www.fortron.net
 
D

David Graham

Hello David,

This is the code as it was published by Toby:
============================ example.php =============================
<!DOCTYPE whatever>
<?php
$s = $_GET['style'];
if (!($s)) { $s = 'red'; }
?>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" media="screen,projection"
<?php echo ' href="styles/' . $s . '.css"'; ?> >
</head>
<body>
<h1>Example</h1>
<p>The style you chose was <code><?php echo $s ?>.css</code>.</p>
<ul>
<li><a href="example.org?style=red">Red</a></li>
<li><a href="example.org?style=white">White</a></li>
<li><a href="example.org?style=black">Black</a></li>
</ul>
</body>
</html>
======================================================================


With regards,
Samuël van Laere
the Netherlands
http://www.fortron.net
Many thanks
David
 
O

Owen Jacobson

Samukl van Laere wrote in alt.html:
Hello David,

This is the code as it was published by Toby:
============================ example.php =============================
<!DOCTYPE whatever>
<?php
$s = $_GET['style'];
if (!($s)) { $s = 'red'; }
?>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" media="screen,projection"
<?php echo ' href="styles/' . $s . '.css"'; ?> >
</head>
<body>
<h1>Example</h1>
<p>The style you chose was <code><?php echo $s ?>.css</code>.</p>
<ul>
<li><a href="example.org?style=red">Red</a></li>
<li><a href="example.org?style=white">White</a></li>
<li><a href="example.org?style=black">Black</a></li>
</ul>
</body>
</html>
======================================================================

One might note that there's a potential security issue with allowing
the user to put anything they want in the $s variable. A more robust
script might look like

<?php
$styletag = $_REQUEST['s']; // explicit import
$stylesheet = "default.css";

// map style tags to actual stylesheets
if ($styletag == 'red')
$stylesheet = "red.css";
elseif ($styletag == 'white')
$styletag = "white.css";
elseif ($styletag == 'black')
$styletag = "black.css";

// Use php echo stylemap('/foo/bar.php'); for all links that should
// propagate style information
function stylemap ($url) {
global $styletag;
return $url . "?s=" . $styletag;
}

.....the rest of your script....
?>
<!DOCTYPE ...>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="<?php echo $stylesheet;
?>">
<link rel="alternate stylesheet" ...alternate stylesheet links...>
</head>
.....the rest of your page....

<a href="<?php echo stylemap('links.php'); ?>">links</a> (for example)

All code untested and written off the cuff
 
T

Toby A Inkster

Owen said:
Samukl van Laere wrote in alt.html:
Hello David,
This is the code as it was published by Toby:
============================ example.php =============================
<!DOCTYPE whatever>
<?php
$s = $_GET['style'];
if (!($s)) { $s = 'red'; }
?> [snip]
<link rel="stylesheet" type="text/css" media="screen,projection"
<?php echo ' href="styles/' . $s . '.css"'; ?> >
[snip]
One might note that there's a potential security issue with allowing
the user to put anything they want in the $s variable.

There is no security issue. So what if the user puts something odd in $s?
It's not like I did an "include($s)".

[newsgroups set back to include alt.html, as I don't read comp.lang.php --
PHP sucks]
 
F

Fabian Neumann

Am 02.11.2003 23:42 schrieb Michael Wilcox:
What exactly is this code?

For example:

<link rel="stylesheet" type="text/css" media="screen" title="default"
href="default.css" />
<link rel="alternate stylesheet" type="text/css" media="screen"
title="redstyle" href="red.css" />
<link rel="alternate stylesheet" type="text/css" media="screen"
title="bluestyle" href="blue.css" />
 
M

Michael Wilcox

Fabian Neumann said:
<link rel="stylesheet" type="text/css" media="screen" title="default"
href="default.css" />
<link rel="alternate stylesheet" type="text/css" media="screen"
title="redstyle" href="red.css" />
<link rel="alternate stylesheet" type="text/css" media="screen"
title="bluestyle" href="blue.css" />

This isn't working for me in a test page. Do you have a working example?
 
M

Michael Wilcox

picayunish said:
Probably you tested with IE.
IE doesn't support alternative stylesheet like NS, Moz, Firebird,
Opera, etc.

Actually I did test in Mozilla, which was why I was confused, but I got it
now (don't know what happened). Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top