Try our conversational search powered by Generative AI!

ContentArea, render odd even classes

Vote:
 

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?

#73558
Jul 29, 2013 11:23
Vote:
 

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) { }

#73565
Jul 29, 2013 16:09
Vote:
 

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?

#73583
Jul 30, 2013 14:00
Vote:
 

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

#73584
Jul 30, 2013 14:37
Vote:
 

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>
                    }

    

#73586
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.