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: [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