根据其值为场设置背景颜色 [英] Set background color for a field depending on its value

查看:136
本文介绍了根据其值为场设置背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户表,其中一个字段是状态 ....我想具有要根据其值设置的包含此字段的单元格的背景颜色,例如状态已关闭的绿色;黄色状态为待定等。

I have a Customer table and one of the fields here is for Status....I want to have the background colour of the cell containing this field to be set according to it's value e.g green for the status "Closed"; yellow for the status "Pending" and so on.

最好的方法是什么?可能会在以后需要修改的东西?

What's the best way to do this...possibly something that'll be easy to modify if need be in future?

推荐答案

在您的css创建类td中,如下所示,考虑到要在html表中显示您的客户表信息,

On your css create class for td as follows, considering you want to display your customer table information in a html table,

td.closed{ color: green; }
td.pending{ color: yellow; }

现在在你的模板上你可以循环你的数据库表在你的html表和td你可以调用css如下:

Now on your template you can loop your database table on your html table and on the td you can call the css as follows:

<td class="{{ status|lower }}">{{ status }}</td>

希望有帮助

这篇关于根据其值为场设置背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆