Customizing SharePoint 2010 global navigation with Css and jQuery – Part III
This is the third post in the series of three articles about how to customize the global navigations with Css and jQuery. This post will cover up following topics:
- Back to roots: The few base classes for the global navigation
- How to extend the global navigation with a drop down menu
- How to extend the drop down with jQuery
- How to use two global navigations with different sitemap providers
Catch up the previous posts here:
Back to basics
In previous articles we looked at how to customize the global navigation in various ways, but now I´d like to lead you back to the basic CSS classes that runs the navigation. No need to get it to complicated, the global navigation can be customized in so many ways regarding the functions as well as look & feel, and there´s not so many classes involved here after all.

At the core there´s only four classes for the navigation list, the menu items, hover and selected. This following CSS contains a most simplified customization of the global navigation, it will change the background color, hover color, selected color and make it a bit higher and more prominent.
/* Navigation list */
.s4-tn{
background-color:#00557B;
padding:0px; margin:0px;
}
/* Global navigation */
.s4-tn li.static > .menu-item{
color:#fff; white-space:nowrap;
border:1px solid transparent;
padding:4px 10px;
line-height:25px;
height:28px;
}
/* Hover */
.s4-tn li.static > a:hover{
background:url("/_layouts/Images/selbg.png") repeat-x left top;
background-color:#0087C1;
color:#000; text-decoration:none;
}
/* Selected */
.s4-toplinks .s4-tn a.selected{
background:url("/_layouts/Images/selbg.png") repeat-x left top;
background-color:#0087C1;
color:#fff; text-decoration:none;
border:1px transparent solid;
padding-right:10px;
padding-left:10px;
margin:0px;
}
Because of this navigation is higher than the OOTB navigation I wanted to specify the vertical align for the search box. The following CSS will also set outlines to none.
/* Position for search */
.s4-search{
padding-top:7px !important;
}
/* Remove dotted outlines */
a:hover, a:active, a:focus { outline:none }
Use and activate drop down menu
First of all you need to use the browser and go to the root site from where you want to display the drop down. Click site settings and navigation and check sub sites. Updated: This will only work for SPS, you have to repalce the SiteMap if its about foundation. See my comment down below.
Secondly you have to modify the menu control in the master page with help of SharePoint Designer. Change the property for MaximumDynamicDisplayLevels from 1 to 2 to get a drop down of two levels.

Css for the drop down menu
There’s basically only one class called dynamic that ULs and LIs use for the dropdown, so if we need to modify the dropdown and specify things like padding, borders or backgrounds it´s quite simple. In this example I use cross browser CSS gradients with a fallback background color for non CSS 3 browsers. When hover items in the dropdown they will be white with a blue text color otherwise they will be gradient in a grey scale.

/* No arrows applies two levels */
.menu-horizontal a.dynamic-children span.additional-background,
.menu-horizontal ul.dynamic a.dynamic-children span.additional-background {
background-image:none;
}
.s4-tn ul.dynamic {
/* UL wrap */
background-image:none;
border-top:0px #ccc solid; border-right:1px transparent solid ;
border-bottom:1px #ccc solid; border-left:1px #ccc solid ;
margin:0px; padding:0px;
}
/* LIs */
.s4-tn li.dynamic {
background-image:none;
border-top:1px #ccc solid; border-right:1px #ccc solid;
border-bottom:1px #fff solid; border-left:1px #fff solid;
}
/* LI menu items */
.s4-tn li.dynamic > .menu-item {
padding:7px 10px;
height:16px;
color:#333;
background-color:#f7f7f7; /* fallback */
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f7f7f7));
background: -moz-linear-gradient(top, #ffffff, #f7f7f7);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7)";
}
/* LI menu items hover */
.s4-tn li.dynamic > a:hover {
color:#00557B;
background-color:#fff; /* fallback */
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#ffffff));
background: -moz-linear-gradient(top, #ffffff, #ffffff);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#ffffff);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#ffffff)";
}
Pimp the drop down menu with jQuery
If you want to let the menu to act slightly smoother when it drop downs then jQuery can be an alternative.
One way could be to use .Animate() that is a part of jQuery API. However in this case I would like to take the advantages of one the many jQuery plugins called Superfish. This plugin is built for unordered lists and works well for the major browsers and it fits nicely into SharePoint 2010.
Go to Superfish site and download the plugin and upload it to your SharePoint environment. Reference to latest jQuery and to Superfish in the master page:
<script src="/Style Library/Jquery/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="/Style Library/MyBlog/superfish.js" type="text/javascript"></script>
Paste following jQuery in the head section of the master page:
<script type="text/javascript">
$(document).ready(function() {
$('.menu-horizontal ul ul ul').superfish({
delay: 1000,
animation: {opacity:'show',height:'show'},
speed: 'nomal',
autoArrows: false,
dropShadows: false
});
});
Use following CSS if you use Superfish:
/* ---- classes for drop down ------- */
/* No arrows applies two levels */
.menu-horizontal a.dynamic-children span.additional-background,
.menu-horizontal ul.dynamic a.dynamic-children span.additional-background {
background-image:none;
}
.s4-tn ul.dynamic {
/* UL wrap */
background-image:none;
border-top:0px #ccc solid; border-right:1px transparent solid ;
border-bottom:1px #ccc solid; border-left:1px #ccc solid ;
margin:0px; padding:0px;
}
/* LIs */
.s4-tn li.dynamic {
background-image:none;
border-top:1px #ccc solid; border-right:1px #ccc solid;
border-bottom:1px #fff solid; border-left:1px #fff solid;
}
/* LI menu items */
.s4-tn li.dynamic > .menu-item {
padding:7px 10px;
height:16px;
color:#333;
background-color:#f7f7f7; /* fallback */
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f7f7f7));
background: -moz-linear-gradient(top, #ffffff, #f7f7f7);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7)";
}
/* LI menu items hover */
.s4-tn li.dynamic > a:hover {
color:#00557B;
background-color:#fff; /* fallback */
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#ffffff));
background: -moz-linear-gradient(top, #ffffff, #ffffff);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#ffffff);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#ffffff)";
}
/* -- Specials -- */
/* I want the second level DD to be close to the first DD */
.s4-tn ul ul ul ul{
margin-left:-2px!important;
}
/* Superfish inside display IE fix */
.menu-horizontal li:hover ul, .menu-horizontal li li:hover ul,
.menu-horizontal li li li:hover ul, .menu-horizontal li li li li:hover ul{
display/*\**/:table-cell\9
}
Two global navigations with different sitemap providers
If you need to have double navigations, for example one for the SharePoint sites and an underlying for another kind of sites or pages you can simply use one more navigation control that reads from a common sitemap file. Let´s try this out!

1. Open the Web.config file for the SharePoint web application with a text editor such as notepad. Be sure to take a copy of this file before editing. Edit this file in a development environment before apply the same for the production environment. No need to perform an IIS reset. Each Web application has one single web config file; you will find it in following directory: C:\inetpub\wwwroot\wss\VirtualDirectories\80\Port_Number. Add the following it the siteMap and providers as a last row.
<add name="CustomNavigationProvider" siteMapFile="/_layouts/1033/styles/CustomNavigationProvider/CustomSiteMap.sitemap" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Edit the Web.config with notepad is an alternative to modify this file but in a real life scenario you should consider modifying the Web.config by a feature. Read more about this in MSDN
2. Create a SiteMap file named CustomSiteMap.sitemap and put it into a new folder with the name CustomNavigationProvider. Add this folder into following directory: \14\TEMPLATE\LAYOUTS\1033\STYLES\CustomNavigationProvider
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="" url="">
<siteMapNode title="About" url="/enterwiki/Pages/Home.aspx"/>
<siteMapNode title="Business" url="/enterwiki/Pages/Home2.aspx">
<siteMapNode title="Business 1" url="/enterwiki/Pages/Home3.aspx"/>
<siteMapNode title="Business 2" url="/enterwiki/Pages/Home4.aspx"/>
</siteMapNode>
<siteMapNode title="Divisions">
<siteMapNode title="Division 1" url="/enterwiki/Pages/Home5.aspx">
<siteMapNode title="Division 1a" url="/enterwiki/Pages/Home6.aspx"/>
<siteMapNode title="Division 2a" url="/enterwiki/Pages/Home7.aspx"/>
<siteMapNode title="Division 3a" url="/enterwiki/Pages/Home8.aspx"/>
</siteMapNode>
<siteMapNode title="Division 2" url="/enterwiki/Pages/Home9.aspx"/>
</siteMapNode>
<siteMapNode title="Resources" url="/enterwiki/Pages/Home10.aspx"/>
</siteMapNode>
</siteMap>
3. Open the master page and search for the content placeholder with the id PlaceHolderHorizontalNav. Replace this placeholder with this code:
<asp:ContentPlaceHolder id="PlaceHolderHorizontalNav" runat="server"> <!-- Original SharePoint ASP menu --> <div> <SharePoint:AspMenu ID="TopNavigationMenuV4" Runat="server" EnableViewState="false" DataSourceID="topSiteMap" AccessKey="<%$Resources:wss,navigation_accesskey%>" UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="2" MaximumDynamicDisplayLevels="0" SkipLinkText="" CssClass="s4-tn" /> <!-- Original sitemap DS --> <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate"> <Template_Controls> <asp:SiteMapDataSource ShowStartingNode="False" SiteMapProvider="SPNavigationProvider" id="topSiteMap" runat="server" StartingNodeUrl="sid:1002"/> </Template_Controls> </SharePoint:DelegateControl> </div> <!-- Second SharePoint ASP menu --> <div class="SecondNavigation"> <SharePoint:AspMenu ID="CustomXmlNavigationAspMenu" Runat="server" EnableViewState="false" DataSourceID="CustomNavigationSiteMapDataSource" AccessKey="<%$Resources:wss,navigation_accesskey%>" UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="1" MaximumDynamicDisplayLevels="3" SkipLinkText="" CssClass="s4-tn-second"> </SharePoint:AspMenu> <!-- Second sitemap DS --> <SharePoint:DelegateControl runat="server" ControlId="CustomXmlMapProviderDelegateControl"> <Template_Controls> <asp:SiteMapDataSource ShowStartingNode="False" SiteMapProvider="CustomNavigationProvider" id="CustomNavigationSiteMapDataSource" runat="server" /> </Template_Controls> </SharePoint:DelegateControl> </div> </asp:ContentPlaceHolder>
Thank you for following this series about branding the global navigation, if you got any questions just post a comment.
Trackbacks & Pingbacks
- Customizing SharePoint 2010 global navigation with Css and jQuery – Part II « Me & My SharePoint Designer
- Customizing SharePoint 2010 global navigation with Css and jQuery – Part 1 « Me & My SharePoint Designer
- SharePoint Daily » Blog Archive » Office Helps Microsoft Earnings; Is WP7 Dead?; Companies Average $6,300 on Cloud Computing
- Customize SharePoint Top Navigation Bar | Sharepoint Sriram

10 thumbs up!
Does this work with Foundation 2010? The reason I’m asking is that I couldn’t find the “Navigation -> Check Sub Sites” option in my Site Settings…
If it doesn’t, then what would be the easiest way to enable dropdown menus in Foundation 2010?
Thanks!
Hi Andrei, no this sentence is for SPS, foundation have some limitations regarding to
the global navigation, I have updated the article now.
One way to get around this could be to use another SiteMapDataSource.
Try to replace the ASP menu in the master page with something like this:
Hi Christian,
great article and thanks for your comment on my blog post on http://www.n8d.at/blog/sharepoint-2010/round-corners-in-top-navigation-of-sharepoint-2010/
I also like your videos very much !!!
Kind regards
Stefan
My eyes are now open! Great job, I am by no means a branding person or designer… fantastic job
Amazing article!
I’ve found a minor error: when you add the custom provider in web.config, the path you give is “…/CustomSiteMap.sitemap” but the file name is “CustomSiteMap.xml”. I had to change the extension of the xml file to get it done.
Also, I got 2 issues with the custom site map:
1. The site map file doesn’t allow two SiteMapNode’s with the same url.
2. The site map file doesn’t allow non UTF-8 characters. If I try to cahnge de codification, I got an error.
Are there any workarounds for those issues?
Thanks. I will keep reading this blog =]
Hi Delphino, thanks for your found, I have now updated the file extensions to .sitemap in the instructions above.
Regarding to your questions:
1: It´s in fact so that you cannot have multiple nodes with the same URL, it´s the XmlSiteMapProvider that requires that the sitemap nodes have unique URLs. The only way I know to overcome this is to use querystring, like SomePage.aspx?p=1
SomePage.aspx?p=2
2: The common way for the sitemap is UTF-8. With this encoded the data values (including URLs) must use entity escape codes for the characters. If you type the URLs direct in the sitemap, you can use UTF-8 (hex) , take a look at this table: http://www.utf8-chartable.de.
Thanks!
Christian
Another question: Can I get rid of the original navigation bar and just use the custom one? I tried to simply replace the providers in the original navigation but it brings me javascript errors.
Thx again.
Delphino, yes you can delete the original navigation and only use the sitemap navigation.
Try this:
I want to bind site map to a sharepoint menu control . Hence i created a CustomNavigationProvider and had an entry like the following in web.config file
and in my master page i had something like this
”
UseSimpleRendering=”true” UseSeparateCSS=”false” Orientation=”Horizontal”
StaticDisplayLevels=”1″ MaximumDynamicDisplayLevels=”1″ SkipLinkText=”"
CssClass=”s4-tn”>
I want to bind my own customized sitemap with the Sharepoint Menu control .Kindly guide me on the following ?.I have my own sitemap and i want to bind it in the Sharepoint menu control that is my objective . Any code snippets,useful links and suggestions would be welcomed ?
Thanks
Anantha rengan.K
Hi anantharengan, if I understand this correct you like to bind you custom sitemap to a SharePoint AspMenu control? If so, check my anwere to Delphino above, it’s just about DataSourceID in the menu control. Let me know if anything is unclear.
Thanks Christian Stahl for the reply . I will work on your solution and get back to you.
Excellent piece! Tremendously helpful!
Hi:
Thanks for your post, However I am getting error message on ” DataSourceID=”CustomNavigationSiteMapDataSource”
Error Message :
Error Parsing Control : The file /_layouts/1033/styles/CustomNavigationProvider/CustomSite.sitemap required by XmlSiteMapProvider does not exist.
Please let me know how to resolve this issue.
Hi there Mr Rishkarthik, It’s seem like that the sitemap file cannot be found. The error message says that your file is CustomSite.sitemap, in my example I used the name ‘CustomSiteMap.sitemap’. Check the names and paths in the web.config and make sure it matches the name of the .sitemap
/ C
Thanks for your response. Now Its workinf fine. you saved me a lot. Thank you. by Karthik.
Good article.. This is so helpfull for me.. But when i am trying this article, i have a problem to show the sub menu from dropdown… Anyway, where i must insert the submenu item??
Thanks before..
Excellent article Mr. Christian Stahl, this is awesome, so helpfull for me.. i was trying this, but there’s some problem when i’m using CustomNavigationProvider to SiteMapProvider, the web is error, i was editing webconfig & creating sitemap.. i dont know where is the error.. But When i’m trying SPSiteMapProvider to SiteMapProvider, the dropdown is showing, but there something i dont want to. Actualy, where i should insert the dropdown item???
Excelente artículo!!
Saludos desde Chile
Fabulous!! We have been trying to find a solution to do this and this worked perfectly. I do have one question. We have a couple of links in our menu that are external. Is there a way to add an attribute to the sitemap file that resembles target=”_blank” in the anchor tab?
Thanking you in advance.
Hi Ken, thanx – If you try like siteMapNode title=”Resources” url=”/SomeSite/Pages/SomePage.aspx” target=”_blank” I think this should work for you?
I am facing the below error message. Please help me on this.
Menu – CustomXmlNavigationAspMenuError parsing control: The DataSourceID of ‘CustomXmlNavigationAspMenu’ must be the ID of a control of type IHierarchicalDataSource. A control with ID ‘CustomNavigationSiteMapDataSource’ could not be found.
Hi Mohan, first I would check the web.config file for a misspelling or character at the wrong place. Otherwise can you provide me with more details on this and did you follow this article or is this a general question about sitemap providers?
/ C
For the CSS dropdown solution, not the tabs or jQuery, how do I actually change what the drop downs say? So the only change to the code I need to make is the MaxDynamicDisplaynumber? The rest can be done with CSS? Should I paste your CSS in the corev4.css file? Or make a new file and reference it in the master page?
Thanks so much!
Hi Christian,
Great article! This is a life saver. But I have a little problem. The highlighted background on the selected menu item never shows when I select the home page. If I select the home page, the highlighted item on the menu points to the tab next to the home tab. Works ok with any other tab I select. Do you know how I can fix that? I am using sharepoint 2010. Thanks. Luiz
Michael, if when it’s about SharePoint server, go to sitesettings / navigation for each site visiblie in the global navigation that has subsites you want to display as dropdowns.
Next thing is to set MaxDynamicDisplaynumber in your custom masterpage. Don’t modify Core.css, create you own CSS file and reference this from the (custom) masterpage or paste the path for the
file in alternate CSS url, http://YourSite/_Layouts/ChangeSiteMasterPage.aspx
Hope this helps!
Luiz, don’t think I have seen this.. Do you use SP foundation?
/ C
Hi Christian, That is awesome!.
I have a question though, can link the original navigation with the sitemap navigation?
Is there a limit for the custom site navigation that I can use?
Thanks sooooooooo much.
Love your blog! But I’m just wondering if you know if it’s possible to activate the double drop-down menu without SharePoint Designer?
Thanks so much!!!
Hi Christian,
amazing article, thanks for posting.
I got a question when I use the two global navigation, the custom one is not getting any css styles.
can you please to fix that. am I missing any thing. the following line of code mention css classes which I dont see in corev4 css or your custom css
CssClass=”s4-tn-second”>
Please let me know where these css classes are…thanks again
Hi Christian, That is nice…
its aweosem work in css menu…
thanks….
Christian,
Great resource. This works perfectly with one expection. It appears _layout pages (or any page that uses the application(v4?).master masterpage don’t inherit these changes. Any ideas why this would happen and how to fix this? This is the one hiccup to us using this in our production environment.
Hi Steve, thanks!
Do you have a custom master and have set this as a site master and a system master? One thing more to check is in Central admin, make sure that the web application is set to yes, see ‘Master Page Setting for Application _Layouts Pages’.
If you still having issues regarded to this, send the master and the css with printscreens describing all steps to sharepointdesigner[at]hotmail.com
/ C
Hi Christian,
I sent you an email, and outlined that I followed all of the steps you mentioned above, and included the exact same CSS that you provided. Everything works fine, except that the global navigation does not display on the safe-guarded _layout application pages:
•AccessDenied.aspx
•MngSiteAdmin.aspx
•People.aspx
•RecycleBin.aspx
•ReGhost.aspx
•ReqAcc.aspx
•Settings.aspx
•UserDisp.aspx
•ViewLsts.aspx
SharePoint is reverting the masterpage to the default top navigation on these pages. Any idea why?
-Steve
Thank you for the great article. My question is…. will this work for Publishing sites? From what I understand the master page and navigation sitemap providers are different Thank you
Thanks for the article, really great.
I have a question, why the selected design is only on the root menu item, even though I selected other menu item.
Hi and thanks for all comments, Ray yes this will work for publishing sites. Adilsuza, it ‘should’ reflect at other menu item that the root items. Have your custom css / masterpage inherit down to sub level sites? Otherwise can you give me a bit more explanation in detail?
/ C
Thanks for the prompt reply, I’ve posted the question in details here http://sharepoint.stackexchange.com/questions/31208/sharepoint-2010-foundation-top-navigation-bar-drop-down-menu
Could you please give it a look. Thanks.
It works great. Thank you for the post. I have a question. How can I change the background of the drop down menu? I mean I want to have different color for each levels of the drop-down menu. Thanks
Hi Volmiro, when it comes to sites that are nestled a bit deep in the site hierarchy, it’s important to specify the cascading of the DOM three exact to handle the styling of global navigation like if some level is differnt from others. The control gives us a special class called li.dynamic-children that can be seen as the third level. You can change the drop down per level with only CSS like this:
.s4-tn ul.dynamic > li.dynamic-children > ul.dynamic > li.dynamic > a {
background-color:red
}
But you cannot just add this with the other classes, you will need to rewrite the other CSS classes a bit to get this working. Try to use only this class and add class to class until you get what you want. Another option is to use jQuery to manipulate the DOM, but try CSS so long as you can before that.
/ C
Christian, thanks for quick reply and thanks for the tip. I have just rewrote the other CSS classes and I have different colors in each sub-levels.
Thanks for the nice article.
I have a question. I donot plan to display subsites in the tree structure. I want to implement tree structure
Ext
A B C
A1
A11
A12
A2
A21
A22
A23
etc. Please let me know.
Thanks,
Ephraim
Hello,
After I activated my master page at site collection level, it sometimes does not show the drop-down menu, when I open the site. What can be the problem? Any ideas? It does not happening all the time, but it will be a problem for the end users.
Thank You
Dear Chris,
Could you please elaborate how to achieve to add sub link under link, as above Department top navigation example.
Thank you
Dear Chris,
Could you please elaborate how to achieve above department top navigation menu ( add sub link under link / nested fly out menu) ?
Thank you.
Chris will this solution work across site collections? After reading many different solutions across the web it seems that getting a global navigation solution that works across site collections can be pretty complicated. Your solution seems so straight forward I’m going to try it anyway! Thanks for the wonderful explainations!