One principle of Web design is the separation between content and presentation. HTML provides the structure of the page, while CSS (Cascading Style Sheets) tells how it should be displayed.
Themes in SharePoint (Site Actions | Site Settings | Site Theme) are a good example. Changing the theme doesn’t modify the structure of your site, it just changes its look by calling a different style sheet.
One key style property is “display”. By setting its value to “none”, we can hide an element, so that our site visitors cannot access it (though the element actually remains in the page structure). “Display=none” is often used to hide buttons or menu options on a page.
The display property can also help optimize space on a Web page. In the following example, I have written a script that allows to hide or show the left menu. This may be useful on dashboard pages for example, where you want to make the best of the available space, but at the same time you don’t want to lose the navigation options.
I am actually publishing two scripts: the first one displays a short text, while the second one is more sober and just shows the +/- icons (Note: your convention for the +/- signs may be different from mine). The screenshots below are from the second script:
You can reuse these scripts for other elements on the page by changing the id of the element (‘LeftNavigationAreaCell’ here). The scripts work in both Internet Explorer and Firefox.
As usual, copy/paste the script in a CEWP.
You’ll notice that such buttons are very responsive, as you don’t make any change to the page structure. Also, another key advantage of using CSS and “display=none” is that it is non-destructive: if later you want your element back, just remove the custom style.
Some helpful tools
When working with styles, one key step is to identify the target element, usually by its id or its class name. In the above example, the left menu is called by its id: ‘LeftNavigationAreaCell’.
From the browser, you can access the source of your Web page by selecting “View source”. A more convenient way is to use a Web editor – SharePoint Designer for example.
Here are two helpful resources on SharePoint CSS:
– the impressive “CSS Reference Chart for SharePoint 2007” compiled by Heather Solomon lists the main class names:
– the interactive “Style under cursor” Web Part by Todd Bleeker:
And here is where you’ll find on your site the style sheet that applies to your SharePoint pages:
To conclude, a reference if you want to learn CSS:
Great post! Convinced me to finally go and get myself a book on CSS and start learning it. The solution itself is really useful – so many times some extra screen real estate makes all the difference.
Pingback: Expand/collapse buttons for your Web Parts « Path to SharePoint
Christophe, would it be possible to save a cookie containing the last known status of the left menu bar (open or closed) to each visitors hard drive and by doing so to save their preference between visits?
I am using the treeview controller provided with WSS – problem is the background colour in the theme applied is too dark – do you know how to get a handle on the treeview.css via your CEWP method?
You mentioned in another blog that you enjoyed challenges – heres one that could be anew article : )
Christophe, you are my hero!
Thanks for sharing.
I really prefer this approach over other CEWP solutions found on the web.
As with this script:
I’m finding that the overflow scroll bars don’t appear when using a Excel Web Access viewer.
Can you help?!
I can’t believe I have missed this solution all this time – I covet every pixel of real estate! thanks Christophe
Is there an updated version of this code for SP 2010?
Styles/CSS and the display property
No, but I’d try a Web search. And let me add this to my to-do list…