我在表格中有一个单元格,看起来像
<td><%= play_result.timestamp.strftime("%H:%M:%S") + ' ' + play_result.status + ':' + ' ' + '[' + play_result.host + ']' + ' ' + play_result.data %></td>
我想编写一个 CSS 类,根据 play_result.status 的值更改此单元格的字体颜色,绿色代表字符串“OK”,橙色代表“CHANGED”,蓝色代表“SKIPPED”红色表示“失败”。
由于我是 Rails 的新手,我该怎么做,我应该在 View 中定义我的 CSS 类还是...?
最佳答案
首先改变你的看法:
<td class="<%= player_result.status %>">
# your code here
</td>
然后,在您的 css 文件中,为每种状态类型制定规则:
.OK {
color: green;
}
.CHANGED {
color: orange;
}
.SKIPPED {
color: blue;
}
.FAILED {
color: red;
}
关于css - 根据值更改表格中的单元格字体颜色 - RoR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059287/