linein designs

06 Feb, 2008

Alternate Background Colors Using PHP

Posted by: john In: javascript|php|programing

background_change.gifYou now can look in almost any website or web application where the background colors are alternating. This is a great (and easy) way to improve the user interface for the end users.

Here’s a quick explanation of what’s going on in the demo file below:

First we set the alternating backgrounds we want to use.

$bg1 = "#f5f5f5";
$bg2 = "#FFFFFF";

Then as we pass through a loop of some kind this code snip rotates the variable $bg to the background colors we set above:
$bg = ($i++ & 1) ? $bg1 : $bg2;

In the example files, we’ve added some javascript to the table
‘s to add an additional hover effect as well as some styling to improve the look of the tables.

Demo | Source File

Comment if you have any questions or suggestions.

Similar Posts:

3 Comments »

Comment by Brenda

Exellent article!!
Can you recomend any calendar PHP without SQL?

Comment by john

I’ve written one about a year ago that I’m hoping to post on here soon. The calendar only includes PHP and some optional javascript. Please check back for the article.

 
 
Comment by laptop satış

very useful information . . .

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post


  • john: There's no easy way to stop it within the InnerFade plugin, but you could just erase all the list items after you've cycled through them using jQuery.
  • Steven: Rachid, did you find an answer? Is there a way to stop by a picture at the end? Can anyone help? Thanks in advance!
  • htc smartphone: WP togo is going to be a great little example of just what kind of super-power these droids will offer like the htc aria and other htc mobile phones l


Please Support Our Friends

Send emails with ease on this SMTP server by JangoSmtp.com.

Banner

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.