Last items of menu different css class

This is a forum to suggest new features for mojoPortal. 

This thread is closed to new posts. You must sign in to post in the forums.
11/22/2009 3:14:38 AM
Nux
Gravatar
Total Posts 183

Last items of menu different css class

Hey Joe,

would it be possible to give the last li from a menu a different style?
Cause when you use some seperators (mostly done in css with a background image), you can't disable it for the last item since it's the same as the rest.
I guess that will not be that difficult, but helpfull ;)

Thanks
Stef

11/24/2009 2:03:32 PM
Gravatar
Total Posts 18439

Re: Last items of menu different css class

No, I do not know a way to do that. When the menu renders there is no indicator or event that can be used to determine if some node is the last one especially because there may be multiple levels of menu showing just a sub tree of a site like on this site where we have 2 horizontal and one vertical menu.

Sorry,

Joe

11/24/2009 2:21:19 PM
Nux
Gravatar
Total Posts 183

Re: Last items of menu different css class

Hey Joe,

I don't understand why you can't do that.
You know the datasource of your repeater, so you know how many items there are.
If you declare a variable outside the ItemDataBound, and increase this variable in the itemDatabound, you will get the last if the variable has the same value as the numbers of items in the datasource (if the start value of the variable is 1), not?

Stef

11/24/2009 2:45:01 PM
Gravatar
Total Posts 18439

Re: Last items of menu different css class

Its not a repeater and we are not simply binding to rows it is a hierarchal tree of sitemap nodes. It is more complicated than you may think. You would have to keep track of nodes at the depth that is the top level of the menu and the css classes are assigned deep inside the menu control adapters not in the menu as it is databinding.

I will ponder it but it's not a trivial request as you may think.

Best,

Joe

11/24/2009 3:08:58 PM
Nux
Gravatar
Total Posts 183

Re: Last items of menu different css class

Ok, I thought it was easier Smile.
If you could find a way, it would be great, but I can understand that there are more important things that this one.

Thanks Joe for the explanation.

Stef

11/24/2009 3:32:48 PM
Gravatar
Total Posts 18439

Re: Last items of menu different css class

fyi, this post on stackoverflow is relevant, and it points to what looks like an easy jQuery solution to the problem.

Best,

Joe

11/25/2009 3:18:30 AM
Nux
Gravatar
Total Posts 183

Re: Last items of menu different css class

Hey Joe,

thanks for this. I will try it this evening.

Stef

4/13/2011 11:43:33 AM
Gravatar
Total Posts 63
Jerry McCreary
SureFire Studios, Inc.

Re: Last items of menu different css class

Joe,

This may be the same question from Nux ...

Is there a way to add a css class to the first child and a class to the last child?

Ex:

<ul>

   <li class="item first"><a href="#">Page 1</a></li>

   <li class="item"><a href="#">Page 2</a></li>

   <li class="item last"><a href="#">Page 3</a></li>

</ul>

 

I'm converting a client's site to mojoportal, and have been looking for a way to do that, in order to match their current design.

(Sorry if this is in the wrong forum)

 

4/13/2011 11:49:01 AM
Gravatar
Total Posts 18439

Re: Last items of menu different css class

The menu nor Treeview controls don't really have anything to detect whether a node is the first or last one so they don't render any different css based on that kind of logic.

However as of mojoPortal 2.3.6.4 we do support custom css classes per page on the body element and on the menu item, so you could manually specify a custom css class for the first and/or last page in your menu.

Hope it helps,

Joe

4/13/2011 1:19:43 PM
Gravatar
Total Posts 63
Jerry McCreary
SureFire Studios, Inc.

Re: Last items of menu different css class

That will probably work.  Thanks.

4/14/2011 2:34:45 PM
Gravatar
Total Posts 355

Re: Last items of menu different css class

Jerry,

Just bouncing through quickly - have a look at http://www.southernbells4equality.com - I used CSS selectors to set a different color for each menu item according to the order of the desired colors.  Is that the kind of thing you're looking for?

4/21/2011 2:11:53 PM
Gravatar
Total Posts 63
Jerry McCreary
SureFire Studios, Inc.

Re: Last items of menu different css class

IndigoTea -

Not what I need, but thanks for the input.   I have a background image applied to the containing <ul> tag of the drop down. I'm need to apply a second background to cap that image. I was thinking to place the cap image as a background to either the top or bottom <li> element.  I may can use javascript to accomplish it.

 

4/21/2011 2:21:53 PM
Gravatar
Total Posts 2253

Re: Last items of menu different css class

Hi Jerry,

You can use the last-child pseudo class to apply style to the last LI. If you can post a link to your site or possibly the generated menu markup, I can give you an exact selector for that last LI.

Thanks,
Joe
 

4/21/2011 2:25:52 PM
Gravatar
Total Posts 355

Re: Last items of menu different css class

Jerry,

What Joe D. says is pretty much what I did; the example is below.  For the dropdowns, just take it to "submenu" instead of "menu", and you should be gravy.  Below is an example of how to create a different menu look for each item in a menu, that will work in IE8 as well as all other civilized browsers. Bon chance! 

 

      <!--[if IE 8]>
    <script language="javascript">
        $('.art-menu li:nth-child(1)').addClass('rainbowRed');
        $('.art-menu li:nth-child(2)').addClass('rainbowOrange');
        $('.art-menu li:nth-child(3)').addClass('rainbowYellow');
        $('.art-menu li:nth-child(4)').addClass('rainbowGreen');
        $('.art-menu li:nth-child(5)').addClass('rainbowBlue');
        $('.art-menu li:nth-child(6)').addClass('rainbowPurple');
        $('.art-menu li:nth-child(7)').addClass('rainbowViolet');
    </script>       
    <![endif]-->

.art-menu li:nth-child(1)
{
    background-color:#e14045;
}

.art-menu li:nth-child(3)
{
    background-color:#e27742;
}
.art-menu li:nth-child(5)
{
    background-color:#f6ac23;
}
.art-menu li:nth-child(7)
{
    background-color:#6aba83;
}
.art-menu li:nth-child(9)
{
    background-color:#6a6ea3;
}
.art-menu li:nth-child(11)
{
    background-color:#bd65c6;
}
.art-menu li:nth-child(13)
{
    background-color:#c83488;
}

/*Because IE8 is a boneheaded sack of poo, and needs to be special*/

.rainbowRed
{
    background-color:#e14045;
}

.rainbowOrange
{
    background-color:#e27742;
}
.rainbowYellow
{
    background-color:#f6ac23;
}
.rainbowGreen
{
    background-color:#6aba83;
}
.rainbowBlue
{
    background-color:#6a6ea3;
}
.rainbowPurple
{
    background-color:#bd65c6;
}
.rainbowViolet
{
    background-color:#c83488;
}

5/5/2011 3:42:31 PM
Gravatar
Total Posts 63
Jerry McCreary
SureFire Studios, Inc.

Re: Last items of menu different css class

Thanks for the suggestions. I wasn't able to get it to work with the project I inherited. (There are hundreds of existing css styles in this project, I think there is some conflicts going on.) Anyway, I was able to use multiple background images (using CSS3) which accomplished what I'm needing.

8/31/2011 6:08:40 AM
Gravatar
Total Posts 50

Re: Last items of menu different css class

if i may,

you can also use last-child pseudo-class, like this:

 

ul li:last-child
{
font-weight:bold


You must sign in to post in the forums. This thread is closed to new posts.