Jump to content

php alternating colour menu


ltoto

Recommended Posts

hi

 

I want to do a dynamic php menu with alternating colours

 

so for example it would be like this

 

Home - blue

Contact - red

About - Blue

News - red

 

Just basically wondering how I would go about doing something like this?

 

Thanks

Link to comment
Share on other sites

I just created this. It has pages and colours in arrays:

 

$colours = array('#0000FF', '#FF0000');
$pages = array('Home' => 'index.php', 'Contact' => 'contact.php', 'About' => 'about.php', 'News' => 'news.php');
$maxcolours = count($colours);
$i = 0;
foreach($pages as $key => $value){
echo '<a href="'.$value.'" style="color: '.$colours[$i].'">'.$key.'</a><br>';
$i++;
if($i > $maxcolours-1){
	$i = 0;
}
}

Link to comment
Share on other sites

Another solution would be:

<?php
$color = '#0000FF';
$pages = array('Home' => 'index.php', 'Contact' => 'contact.php', 'About' => 'about.php', 'News' => 'news.php');
foreach($pages as $key => $value){
echo '<a href="'.$value.'" style="color: '.$color.'">'.$key.'</a><br>';
        $color = ($color == '#0000FF')?'#FF0000':'#0000FF';
}
}?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.