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: [northernpenguin] Changing Background Color of List Field

By Chris - November 26, 2010

Hi northernpenguin,

If you're writing HTML, it's as simple as a little CSS: [url http://pietschsoft.com/post/2004/09/20/Color-the-background-of-items-in-a-Dropdown-box-in-your-HTML-pages.aspx]http://pietschsoft.com/post/2004/09/20/Color-the-background-of-items-in-a-Dropdown-box-in-your-HTML-pages.aspx[/url]

If you're asking about how to change the background colours of list field options inside the CMS Builder interface, there's currently no way to do that. It would be possible with a little bit of custom programming — please let me know if that's something you're interested in.
All the best,
Chris

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