扩展这个很好的问题:Color coding cells in a table based on the cell value using Jinja templates
我们如何才能将其仅应用于表格的特定列? IE。例如第二列。
最佳答案
当您迭代一行中的元素(即一行中的列)时,您可以使用 loop.index0
或 loop.index
设置所需列的样式。
例如,如果你输入 {% if loop.index == 2 %} <td class="special-colour"> {{ item }} </td>{% endif %}
在你的里面 {% for item in row %}
循环,.special-colour
类将仅适用于第二项。
关于css - 使用 Jinja2 根据单元格值对表格中的单元格进行颜色编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56941376/