[Service portal] Change the style of the menu item for current page

Community Alums
Not applicable

Hello community,

Is it possible to apply a specific CSS class for the menu item of the active page ?

find_real_file.png

Regards

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi everyone and thanks a lot for your answers.

 

Finally, we have found a solution to apply a specific CSS class on the menu item link active based on the current page ID.

 

To do it, we just added this code in the CSS include of the theme :

.navbar-nav > li > a.active {   
       color:   #f00;
}

The widget "Header Menu" compute the menu content and use the related ng-template "menuTemplate" to generate all menu items HTML.

 

So, in the menuTemplate ng-template, we have replaced

<a ng-if="item.items.length == 0 && !item.scriptedItems" ng-href="{{item.href}}" target="{{item.url_target}}" title="{{item.hint}}" >
  <fa ng-if="item.glyph" name="{{::item.glyph}}"></fa>
  <span ng-bind-html="item.label"></span>
</a>

By

<a ng-if="item.items.length == 0 && !item.scriptedItems" ng-href="{{item.href}}" target="{{item.url_target}}" title="{{item.hint}}" ng-class="{ 'active':item.href.indexOf('?id='+$root.page.id) >= 0 } ">
  <fa ng-if="item.glyph" name="{{::item.glyph}}"></fa>
  <span ng-bind-html="item.label"></span>
</a>

It works fine.

 

 

 

Regards

 

View solution in original post

25 REPLIES 25

Justin Abbott
Giga Guru

Are you talking about inside the breadcrumbs or in the navigation header?


Community Alums
Not applicable

Hi Justin,


I'm talking about the navigation header. I have updated the attached picture 😉


Hi Christophes



I think you can work on the CSS include uses by your portal.


Of course you need to check the header widget structure (classes/ids) in order to over ride the OOB CSS.



Panzerkunst___ServiceNow.png



I hope this will help/answer your question and if it does please mark it



Cheers


R0b0


Community Alums
Not applicable

Hello R0b0,


yes we currently use CSS include to customize the header, footer...


But my question is to identify the menu item linked to the current page and just apply the style to it.



Christophe