【问题标题】:Render table with Meteor Handlebars template so that rows have different colors使用 Meteor Handlebars 模板渲染表格,使行具有不同的颜色
【发布时间】:2014-02-11 18:24:50
【问题描述】:

如何以这样的方式呈现带有把手模板的表格,使得每个奇数行的颜色与每个偶数行的颜色不同?

有没有办法在{{#each}} 语句中获取数组索引,或者我应该在模板帮助方法中设置索引属性?

【问题讨论】:

  • 您可能应该为此使用 CSS(第 n 个子选择器 + 偶数/奇数规则)。检查此链接w3.org/Style/Examples/007/evenodd.en.html 和谷歌。
  • 我总是使用 JS 来为行着色,但这似乎是一个更清洁的解决方案。谢谢!

标签: javascript meteor handlebars.js


【解决方案1】:

最简单的方法是通过nth-child选择器:

.my-table tr:nth-child(2n+1) {
  background: orange;
}

.my-table tr:nth-child(2n+2) {
  background: orangered;
}

除了 IE see here之外的所有浏览器都可以理解。

【讨论】:

    猜你喜欢
    • 2012-09-08
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 2013-01-22
    • 1970-01-01
    • 2013-04-07
    • 2014-01-03
    相关资源
    最近更新 更多