<% @projects.each_with_index do |project, i| %> <% row_class = i%2 == 0 ? "even" : "odd" %> <tr class="<%= row_class %>"> ...... <% end %>
In the CSS:
TR.even { background-color: #f00; } TR.odd { background-color: #f00; }
etc..
11382 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
<% @projects.each_with_index do |project, i| %> <% row_class = i%2 == 0 ? "even" : "odd" %> <tr class="<%= row_class %>"> ...... <% end %>
TR.even { background-color: #f00; } TR.odd { background-color: #f00; }
table tr.rowA {background-color: white; } table tr.rowB {background-color: silver; }
<% @projects.each do |project| -%> <tr class="<%= cycle('rowA', 'rowB') %>">...</tr> <% end -%>
You need to create an account or log in to post comments to this site.
1 - your two css statements have the same color background...
2 - I think there's a DRYer way:
And in the css :