Currently I have 4 spans with alternating CSS tags.
<% var index =0 ; %>
<% foreach (var item in Model.Take(4)) {
var css = (index%2==0)?"even":"odd";
%>
<span class="featured-products <%= css %>">
<a href="<%= Url.Action("View", "Products", new {id = item.SKU}) %>"><%= Html.Photo(PhotoExtensions.PhotoSizeType.HomepageThumb, item.DefaultPhoto)%></a>
<a href="<%= Url.Action("View", "Products", new {id = item.SKU}) %>"><%= item.ProductName%></a>
</span>
<%
index ++ ;
} %>
But I need for the last span to contain an extra CSS tag “last”. Ive tried a couple of different methods but they all failed. Any help? Thanks.
Have you tried using the :last-child CSS selector? It may not be necessary to add additional markup if you can achieve what you want through CSS.