Try our conversational search powered by Generative AI!

ContentArea, render odd even classes



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?

Jul 29, 2013 11:23

My first suggestion would be to use the nth-child CSS selector. See for browser support.

:nth-child(odd) { }

:nth-child(even) { }

Jul 29, 2013 16:09

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?

Jul 30, 2013 14:00

I suppose you could set the class names using jQuery. That should handle your IE8 problems as well.

Jul 30, 2013 14:37

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);


Jul 30, 2013 14:47
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.