6

I am using the following css to hide the quick launch in SharePoint 2013, but I want it to hide the quick launch only in the root site, NOT in the subsites which inherit the same master page.

 #sideNavBox {DISPLAY: none}
 #contentBox {MARGIN-LEFT: 10px}

Is there a way to apply this css only to the root site?

2
  • Do the subsites inherit navigation?
    – Pantani
    Jan 6, 2016 at 9:14
  • Yes, and they inherit the master page as well Jan 6, 2016 at 9:35

1 Answer 1

3

I would recommend adding a custom action to the web object at the root. The guys at pattern and practice explains it well

Basically create a css file with what you need, put it somewhere and add the custom action

using (var clientContext = new ClientContext(rootUrl))
{
    clientContext.Credentials = new SharePointOnlineCredentials(username, pwd);

    var web = clientContext.Web; // use this one
    var site = clientContext.Site;

    // Build a custom action to write a link to our new CSS file
    UserCustomAction cssAction = web.UserCustomActions.Add();
    cssAction.Location = "ScriptLink";
    cssAction.Sequence = 100;
    cssAction.ScriptBlock = @"document.write('<link rel=""stylesheet"" href=""" + assetLibrary.RootFolder.ServerRelativeUrl + @"/contoso.css"" />');";
    cssAction.Name = actionName;

    // Apply
    cssAction.Update();
    clientContext.ExecuteQuery();
2
  • I would like to apply this css only to the root site and not to the subsites. Jan 6, 2016 at 10:43
  • If you use the web object of the root url and not the site object it should only be the root site. Please see the updated codesnippet
    – Pantani
    Jan 6, 2016 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.