0

I'm using the following code to hide the left hand navigation in SharePoint:

<style type="text/css">
 #s4-leftpanel {
    display:none !important;
 }
 .s4-ca{
    margin-left:0px !important;
 }
</style>

This works great but the issue is when the page loads you can initially see the left hand menu for a few seconds but the code kicks in and it gets hidden. I don't want to see the menu on page load for a few seconds. Is that possible?

EDIT: I should have mentioned more details. I'm doing this within a custom web part. I only want the left hand navigation gone when this web part is applied to a page. I put this CSS within the web part itself.

2
  • How did you apply the CSS code?
    – Sig Weber
    Mar 2 '12 at 20:34
  • Through a custom web part.
    – daver306
    Mar 2 '12 at 21:06
3

You should insert your style inside "head" tag of page.

By the code you can do it so:

Page.Header.Controls.Add(new LiteralControl("<style type=""text/css""> #s4-leftpanel {display:none !important;} .s4-ca{ margin-left:0px !important;} </style>"));
4
  • I should have mentioned more details. I'm doing this within a custom web part. I only want the left hand navigation gone when this web part is applied to a page. I put this CSS within the web part itself. I updated the original question to reflect this.
    – daver306
    Mar 2 '12 at 21:12
  • I have added an example.
    – Aviw
    Mar 2 '12 at 21:15
  • Cheers! I had to wrap the CSS elements with a <style> tag but it worked great. Thank you!
    – daver306
    Mar 2 '12 at 21:23
  • Oh, sure. I have forgotten about style tag, sorry. :)
    – Aviw
    Mar 2 '12 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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