css - CSS td 条件背景色设置
问题描述
假设我有以下角度表
<table>
<tr *ngFor="let company of investTable; let i = index">
<td>
{{company.name}}
</td>
<td>
{{company.price}}
</td>
<td>
{{company.profit}}
</td>
</tr>
</table>
如何根据单元格值制作一个简洁的解决方案,让表格单元格具有背景颜色?可以说,如果公司利润为正,则将其设为绿色。
解决方案
在 CSS 中
td.highlight {
background-color: green;
}
在 html 中:-
<table>
<tr *ngFor="let company of investTable; let i = index">
<td>
{{company.price}}
</td>
<td [ngClass]="{'highlight': company.profit > 0}">
{{company.profit}}
</td>
</tr>
</table>
推荐阅读
- hugo - 在 Blogdown 中手动订购项目
- codeigniter - Codeigniter ion auth 用户管理同时创建一个新用户
- macos - 路径 /ASP.NET/Https 和 /Microsoft/UserSecrets)未在 OS X 上共享
- excel - 如何在 Powershell 中的 Excel 表格的总计行上设置 Sum?
- python - 重新组合熊猫 df 中的列值
- reactjs - 字符串比较是为 React-JSS 中的变体进行动态样式设置的正确方法吗?
- laravel-5 - 如何从 Laravel 5.7 自定义邮箱验证邮件?
- android - 如何从 Java 中的 Native Android Activity 打开我的 React Native 应用程序的特定组件?
- firebase - Firebase 实时数据库规则中“.children”属性的用途是什么
- express - 快速路由正则表达式 - 正确的语法