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:


Related Posts:
  1. Run Javascript Code After an AJAX Request
  2. jQuery Loading – Display Images or Text Until Script is Finished

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



Please Support Our Sponsors

A Payday advance can be a great way to get back on track.

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.