Page 1 of 1

Code to generate alternative CSS

Posted: Thu Mar 11, 2004 6:55 pm
by mrvanjohnson
Just looking for a little help with code clean up. Been hacking around with this and it works great but it looks too sloppy. I was wondering if there might be a better way of doing this. Here's the story, the people access the site have a high percentage of elderly. To make the site more accessible, I added a button that then loads an alternative CSS file with basically just larger fonts. Loads the preference in a session and follows them around while they are on the site. Like I said, I got it working but there must be a better way of doing it... Any suggestions? Here is how I got it working.

Code: Select all

<?php
	session_start();
	if ($_REQUEST['zoom'] == "off"){
		session_unregister('zoom');
		$css_image = "css_plus.gif";
		$css_image_var = "on";
		$css_image_alt = "View larger fonts for easier viewing";
		$css_sheet = "gsfcu_style.css";
	}elseif ($_SESSION['zoom'] == "on"){ 
		$css_image = "css_minus.gif";
		$css_image_var = "off";
		$css_image_alt = "View normal sized fonts";
		$css_sheet = "gsfcu_style2.css";
	}elseif ($_REQUEST['zoom'] == "on"){
		$zoom = "on";
		session_register('zoom');
		$css_image = "css_minus.gif";
		$css_image_var = "off";
		$css_image_alt = "View normal sized fonts";
		$css_sheet = "gsfcu_style2.css";
	}elseif (!($_SESSION['zoom'])){
		$css_image = "css_plus.gif";
		$css_image_var = "on";
		$css_image_alt = "View larger fonts for easier viewing";
		$css_sheet = "gsfcu_style.css";;
	}
	
?>

Posted: Thu Mar 11, 2004 9:58 pm
by graphicmd
I use two stylesheets on my website also. One to add the navigtion to the right side of the page, and one to add the navigation to the left. I actually use JavaScript to do this, but PHP would be much cleaner.

This might work for you.

Code: Select all

<?
if (isset($_COOKIE['style'])) {
	$style = $_COOKIE['style'];
} else {
	$style = "css_page1.css";
}
?>
<link rel="stylesheet" type="text/css" media="screen" href="<?= $style ?>" />