My first suggestion would be to use the nth-child CSS selector. See http://caniuse.com/#feat=css-sel3 for browser support.
:nth-child(odd) { }
:nth-child(even) { }
Unfortunately we need to support IE8, else your suggestion would be perfect. I really need to add two different classes to make this work. Seems like I need to make my own rendered?
I suppose you could set the class names using jQuery. That should handle your IE8 problems as well.
You could also do it the "old way": make a list of view models in your backend and instead of having Html.PropertyFor(m => m.ContentArea) have a foreach that sets odd/even classes and call Html.RenderPartial. This is, if you are rendering the same children type.
For example:
@foreach (var item in widgets.Widgets)
{
<ul class="@(item.IsOdd ? "odd" : "even")">
Html.RenderPartial("Blocks/ListingTeaserBlock", item);
</ul>
}
Hi
Is it possible to add "odd" and "even" CSS classes to a contentareas children? like when you set ChildrenCssClass on rendersettings? Or do I need to write my own custom rendering?