Changing Background Color of List Field

6 posts by 2 authors in: Forums > CMS Builder
Last Post: November 30, 2010   (RSS)

Does any one know of a way to change the background color of an item in a list field? For example, I have a list field called "status". I would like each entry to have a different background color. Is there any way to do this?
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [chris] Changing Background Color of List Field

Thanks Chris. I'll check the HTML solution.
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [chris] Changing Background Color of List Field

Chris: the HTML solution is partially what I was looking for. Let me explain. Lets say I have a list field in CMSB called "status", and its list values are: One, Two, Three, Four, Five

I want the value for "One" to display on the webpage as "One' with a red background; "Two" with a green background, "Three" with a purple background, etc.

So, I believe that I need to include some php code to check the value of "status" and, depending upon the value, set the background color.

Does that make sense?
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Changing Background Color of List Field

By Chris - November 29, 2010

Hi northernpenguin,

You can use IF statements to do this:

<?php
$css = '';
if ($record['status'] == 'One') { $css = 'background-color: red;'; }
elseif ($record['status'] == 'Two') { $css = 'background-color: green;'; }
elseif ($record['status'] == 'Three') { $css = 'background-color: purple;'; }
elseif ($record['status'] == 'Four') { $css = 'background-color: blue;'; }
elseif ($record['status'] == 'Five') { $css = 'background-color: orange;'; }
?>

<div style="<?php echo $css; ?>">
<?php echo htmlspecialchars($record['status']); ?>
</div>


Does this help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Changing Background Color of List Field

Thanx again, Chris.

It worked perfectly.
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke