简体   繁体   中英

Render table with Meteor Handlebars template so that rows have different colors

How can I render a table with a handlebars-template in such a way, that each odd row has a different color than each even row?

Is there a way to get the array index within the {{#each}} statement or should I set an index property in the templates helper method?

The easiest way to achieve this is via nth-child selectors:

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

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

It's understood by all browsers except IE <= 8, see here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM