[SOLVED] Adding a class on last child of a submenu ?

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
User avatar
Trangsene
Forum Members
Forum Members
Posts: 19
Joined: Thu Aug 28, 2008 9:43 am

[SOLVED] Adding a class on last child of a submenu ?

Post by Trangsene »

Hello,
I'm using cssmenu.tpl and I would like to have a class "last" on the last child of a submenu to have no separator after it.

Here is the cssmenu code :

Code: Select all

{* CSS classes used in this template:
#menuwrapper - The id for the <div> that the menu is wrapped in. Sets the width, background etc. for the menu.
#primary-nav - The id for the <ul>
.menuparent - The class for each <li> that has children.
.menuactive - The class for each <li> that is active or is a parent (on any level) of a child that is active. *}
{if $count > 0}
<div id="menuwrapper">
<ul id="primary-nav">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string='<ul class="unli">' times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string='</li></ul>' times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->parent == true or ($node->current == true and $node->haschildren == true)}

<li class="menuactive menuparent">
<a class="menuactive menuparent" {elseif $node->current == true}
<li class="menuactive">
<a class="menuactive" {elseif $node->haschildren == true}
<li class="menuparent">
<a class="menuparent" {elseif $node->type == 'sectionheader' and $node->haschildren == true}
<li class="sectionheader"><span class="sectionheader">{$node->menutext}</span>{elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="menu_separator" />{else}
<li>
<a {/if}
{if $node->type != 'sectionheader' and $node->type != 'separator'}
{if $node->target}target="{$node->target}" {/if}
href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->type == 'sectionheader'}
><span class="sectionheader">{$node->menutext}</span></a>
{/if}
{/foreach}
{repeat string='</li></ul>' times=$node->depth-1}
</li>
</ul>
<div class="clearb"></div>
</div>
{/if}
After this:

Code: Select all

{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
I need to have the total of the children of the current node and test if we have reached the last child in order to write "<a href..."

I'm searching a solution for hours, did anyone try to solve this problem and succeed ?
Help would be much appreciated.

Thanks in advance.
Last edited by Trangsene on Mon Oct 26, 2009 5:35 pm, edited 1 time in total.
Connie

Re: Adding a class on last child of a submenu ?

Post by Connie »

I think you are a little bit away from the solution, but not too far...

think of "pseudo-classes" and use "last child" instead.. the system will find automatically the last one ;=)

Code: Select all

li:last-child{color:#ff0000}
User avatar
Trangsene
Forum Members
Forum Members
Posts: 19
Joined: Thu Aug 28, 2008 9:43 am

Re: Adding a class on last child of a submenu ?

Post by Trangsene »

Thanks, I know last and first-child in CSS but this won't work in IE6 and this website has to :-(
Anyway having a code based solution would be interesting for other uses.
Connie

Re: Adding a class on last child of a submenu ?

Post by Connie »

this won't work in IE6 and this website has to :-(
Is this really true? Shouldn't webworkers stop to support this shitty browser?

Time has come, or do the people are still on WIN 3.11 and read newspapers from 1997?

Cheers., and good luck,

Connie
Ziggywigged
Power Poster
Power Poster
Posts: 424
Joined: Sat Feb 02, 2008 12:42 am
Location: USA

Re: Adding a class on last child of a submenu ?

Post by Ziggywigged »

Take a penny, leave a penny.
User avatar
Trangsene
Forum Members
Forum Members
Posts: 19
Joined: Thu Aug 28, 2008 9:43 am

Re: Adding a class on last child of a submenu ?

Post by Trangsene »

Generally I prefer avoid this kind of js solution if I can.
This time I think this will be the quicker way.
Thanks four your answers.

Anf for information first-child is understood by IE8 but last-child absolutly not !
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: [SOLVED] Adding a class on last child of a submenu ?

Post by Dr.CSS »

You could try this one from Calguy, you can change the menuparent etc. if need be...

{if $count > 0}


{* begin calguy *}
{foreach from=$nodelist item=node name='menu'} 
{assign var='last' value=''}
{if $smarty.foreach.menu.last}
  {assign var='last' value='last '}
{/if}
{* end calguy *}
{if $node->depth > $node->prevdepth}

{repeat string="" times=$node->depth-$node->prevdepth}
{elseif $node->depth prevdepth}

{repeat string="" times=$node->prevdepth-$node->depth}

{elseif $node->index > 0}
{/if}
{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
current == true}
haschildren == true}
type == 'sectionheader'}
        {$node->menutext}
{elseif $node->type == 'separator'}
       
{elseif empty($last)}
        {* not the last menu item, but not a separator, header, parent, or active either *}
        type != 'sectionheader' and $node->type != 'separator'}
href="{$node->url}" {if $node->accesskey != ''}accesskey="{$node->accesskey}" {/if}{if $node->tabindex != ''}tabindex="{$node->tabindex}" {/if}{if $node->titleattribute != ''}title="{$node->titleattribute}"{/if}{if $node->target ne ""} target="{$node->target}"{/if}>{$node->hierarchy}: {$node->menutext}
{elseif $node->type == 'sectionheader'}
>{$node->hierarchy}: {$node->menutext}
{/if}

{/foreach}

{repeat string="" times=$node->depth-1}



{/if}
Post Reply

Return to “Layout and Design (CSS & HTML)”