List Rows - Alternating Background Colours

4 posts by 3 authors in: Forums > CMS Builder
Last Post: April 7, 2008   (RSS)

By Perchpole - April 2, 2008

Hi, Dave -

I noticed that you'd recently given someone a little help configuring rows on a list page. It got me thinking about an issue that web designers often come up against when dealing with lists: namely, an expedient method for alternating the background colour of each row.

I wondered if there was any trick in php that we could exploit to enable us to do this in CMS Builder?

[unimpressed]

AJ

Re: [Perchpole] List Rows - Alternating Background Colours

By Dave - April 2, 2008

Here's a little shorthand PHP I often use:

<?php $bgColor = (@$bgColor == "#CCCCCC") ? '#EEEEEE' : '#CCCCCC'; ?>

Just replace the '#CCCCCC' and '#EEEEEE' with the colors you want and put that just below the start of your foreach loop. Then you can print out the bgColor value like this:

bgcolor="<?php echo $bgColor; ?>"

You could also use that to rotate a classname if you want to use CSS for your background color.

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] List Rows - Alternating Background Colours

By Perchpole - April 3, 2008

Brilliant.

Now you're just showing-off!

[;)]

AJ