web.0
  • Home
  • Services
  • Portfolio
  • Blog
  • Contact

Fixed width layouts, the scrollbar and the ribbon in SharePoint 2010. A better way?

Posted on October 6, 2010 by web.0

The ribbon is a massive deal in SharePoint 2010. It is a big deal in all of the Microsoft Office suite, but especially so in SharePoint Server 2010.  And it is a fundamental change to the user experience for everyone. As designers we have to start to tailor our site styles to accomodate its inclusion, and as developers we need to learn how to work with it, rather than against it in order to make for a useful user experience. This is especially true in intranet deployments, where we do a lot of our work, as the ribbon will almost certainly be there all the time.

However, lately we’ve come across a bit of a problem with the ribbon and the current fashion in web design, the fixed width layout. Everyone wants a fixed width layout these days, even on intranets, and there are a lot of really good arguments for having them. There is even a simple way built in to SharePoint 2010 to allow you to turn off the default behaviour of taking up the full width of the browser window. You’ll find plenty of blogs out there telling you how to do this, but personally I’d recommend you just head over to Randy Drisgill’s blog and pick up his starter master pages, as they are not only extremely useful when making custom sites, but also have some great comments in them to tell you where to edit for things like fixed width layouts. Or if you just want the info on setting the fixed width start at his other post here, and go from there.

UPDATE 23/11/2010: This article has been updated as some issues were found with some of the popdown menus on the ribbon when using this method. We have fixed this here using jQuery and a timer, which is not ideal, as ultimately it would be better to use the existing sharepoint core javascript methods (if possible) to position items correctly in the first place. We have been looking through the debug versions of the core javascript, but they are almost completely undocumented and mostly minified so it’s pretty slow going, so you may consider this as an option in the interim. It’s your choice whether or not to use it at the end of the day, and if anyone has any suggestions or help getting over this final hurdle, I’m all ears!

Back to the problem. When you add the class ‘s4-nosetwidth’ to the container with the ID ‘s4-workspace’, and then set a fixed width for your container using CSS, this happens;

SharePoint 2010 scrollbars look wrong with fixed width layouts

Ouch. That’s not pretty. Nor is it where your users expect the scrollbar to be, so they won’t like it either. There are a couple of things you can do here; You could unfloat the ribbon. That way you can use CSS to put the scrollbar back where it should be and your users will feel at home. But, some of the ribbons usefulness is lost. Or  you could add a wrapping container inside the ‘s4-workspace’ container and then fix the width of that instead. This works but still uses a non standard scrollbar that doesn’t look quite right.

The scrollbar is in the right place, but doesn't extend to the top of the window properly

We think there is another way. One that allows the ribbon to float, allows the page to use the scrollbar the user is expecting in the place they are expecting it, and look correct. And in essence it’s quite simple. Position: fixed to the rescue.

To achieve this you are going to need to edit your master page, have some custom CSS, and some custom javascript. If you can do all these things, then here’s how it is done. This has been tested as working in IE7 and 8, Firefox 3, Safari 5, and Chrome 6

  • Edit your master page in something like Microsoft Office SharePoint Designer and add the class ‘s4-nosetwidth’ to the conatiner with the ID ‘s4-workspace’. Also remove the attribute scroll=”no” from the body tag (this is important for IE7). Add your custom CSS, a link to jquery and your custom javascript file references. There are lots of posts around that can explain how best to do this, but some quick example code is below. Make sure your custom css is loaded after the core SharePoint CSS files.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<SharePoint:ScriptLink language="javascript" name="<your path>/<your custom js>.js"  runat="server"/>
<SharePoint:CssRegistration name="<your path>/<your custom css>.css" After="corev4.css" runat="server"/>
  • Add the following classes to your CSS file to reset the scrollbar to normal, fix the position of the ribbon, and float it over the items below it.
/* make the body use it's proper scrollbar again */
body {
overflow: auto !important;
}
/* fix the width of the workspace, centre it and turn off its scrollbar. Also add a default padding to the top to cope with the ribbon in its standard form */
body #s4-workspace {
width: 980px;
margin: 0 auto;
overflow: visible;
padding-top: 44px;
}
/* fix the position of the ribbon, float it above the content and allow it to grow when it's height changes */
body #s4-ribbonrow {
position: fixed;
left: 0;
top: 0;
z-index: 10;
overflow-y: visible;
}
  • Almost there. Lastly, we need to add in a bit of custom javascript to cope with the way the ribbon now hides the top of the page, as well as it’s default behaviors of changing height dynamically and hiding the title row when certain tabs are clicked. There is a method within the core init.js file which we can use to tie our function in to ribbon resizes, and we should use padding rather than margin because IE7 copes with it better, so add the following to your javascript file. Also add your jQuery based timer function here to cope with the popdown positioning issue described above.

// function to reset the top margin to whatever the current height of the ribbon is
function setTopPadding() {
var myElem = document.getElementById('s4-workspace'), newHeight = document.getElementById('s4-ribbonrow').offsetHeight;
myElem.style.paddingTop = newHeight + 'px';
}

function setTopPos() {
 $('.ms-cui-menu, .ms-cui-tooltip').each(function(){
 var newTop = $(this).data('origTop') || $(this).position().top;
 $(this).data('origTop',newTop);
 newTop += $('#s4-ribbonrow').position().top;
 $(this).css({
 top : newTop
 });
 });
 }

// bind top padding reset to ribbon resize event so that the page always lays out correctly.
ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Workspace.add_resized(setTopPadding); }, "init.js");

$(document).ready(function(){
 setInterval(setTopPos, 300);
 });

And once you have this all together, you end up with this!

The right scrollbar in the right place looking correct, so it’s what your users expect with no loss in functionality. It looks right if you fix the width of the ribbon too, which some briefs also require (although there are a whole wealth of issues to consider when doing this in order to cope with the way javascript is used so heavily to customise the ribbon, so be careful and test test test). And there you have it, our better way to scrollbars on fixed width layouts. We would be interested in your thoughts about this option!

Share this:
  • Print
  • LinkedIn
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Buzz
  • Google Bookmarks
Posted in General, SharePoint design and development | Tagged CSS, Javascript | 29 Comments
  • Jonathan Mezach

    This looks great, but I’m having some trouble with the pop-ups and drop down menu’s on the Ribbon now. When I scroll down my page and click on the “Alert Me” drop down for instance it doesn’t show up. But if I go to the top of the page and click on the “Alert Me” button it does come up. Any fix for that?

    • http://www.webpoint0.com Ben

      Hi Jonathan,

      Thanks, glad you like it. Yes there is a fix for the issue you described, it was picked up in our testing too. It’s a quick fix at the moment until we can find a more solid solution, but I’ll try and update the blog post with the additional code in the next day or so, and that will hopefully help.

    • http://www.webpoint0.com web.0

      Hi Jonathan,

      The update I mentioned has now been posted.

      • Mark Pitts

        I think the following issue is also related to ribbon drop-downs.
        I am having one issue when I tested this solution, which I hope you can offer some insight.When I try inserting ‘reusable content’ onto a page, using the ribbon (insert->reusable content), as I hover my mouse through the list of reusable content, often the content gets inserted right away, instead of simply presenting it as a preview. When this happens, the reusable content flyout menu closes – in the same way as if I actually clicked on a reusable content.The behaviour only happens in IE – the other browser I am testing with is FireFox does not have this issue.When I remove your solution, the reusable content behaves as expected.Cheers!Mark

        • http://www.webpoint0.com web.0

          Hi Mark,
          That’s strange. There’s nothing in the code emulating a click anywhere, so not sure why that should be happening for you. I’ve tried to recreate this in IE9 but I can’t I’m afraid. Neither can in IE8 or IE7 modes. Which version of IE are you using?

          • Mark Pitts

            IE9. I determined that the problem occurs when the reusable content HTML is vertically long. The content has to be vertically tall enough to populate beyond the physical fold of the page. If the reusable content vertical real estate is short enough, then I don’t see the problem.

            I hope my explanation helps provide more insight.

          • http://www.webpoint0.com web.0

            Ok thanks for the info, I’ll try that out soon and see if I can recreate the issue.

          • http://www.webpoint0.com web.0

            Hi Mark,

            I’ve given this a try now using a very long piece of reusable content (basic stuff, just 8 paragraphs of Lorem Ipsum text), and it still seems to work fine for me I’m afraid. If you are happy to send me the html in your reusable field and try it with that as a like for like comparison?

          • Mark Pitts

            An example of the reusable content, of which there are many similar to these stacks images on top of each other. The trick is that the content would, upon preview, cause the page to expand significantly.

            <div class="html-5-rotator">    <div id="fiveRotator">        <div>            <img src="/Style%20Library/test/images/DemoContent/80×80-thumbs/building.jpg" alt="#" /><br/><a href="#"><span>Insert caption here</span></a>        </div>        <div>            <img src="/Style%20Library/test/images/DemoContent/80×80-thumbs/buildingFacade.jpg" alt="#" /><br/><a href="#"><span>Insert caption here</span></a>        </div>        <div>            <img src="/Style%20Library/test/images/DemoContent/80×80-thumbs/capitol.jpg" alt="#" /><br/><a href="#"><span>Insert caption here</span></a>        </div>        <div>            <img src="/Style%20Library/test/images/DemoContent/80×80-thumbs/philliesStadium.jpg" alt="#" /><br/><a href="#"><span>Insert caption here</span></a>        </div>        <div>            <img src="/Style%20Library/test/images/DemoContent/80×80-thumbs/stadium.jpg" alt="#" /><br/><a href="#"><span>Insert caption here</span></a>        </div>        <div>            <img src="/Style%20Library/test/images/DemoContent/80×80-thumbs/building.jpg" alt="#" /><br/><a href="#"><span>2 row<br/>caption</span></a>        </div>    </div></div>

            Cheers!

          • http://www.webpoint0.com web.0

            Ok, I’ve put this in to our dev environment now and can confirm I’m seeing the same issue you are. It appears to be caused by the ‘overflow: visible’ style declaration being made against the ‘body #s4-workspace’ selector. If this is reset to auto, it works fine again. However, you get the horrible scrollbar back. The only thing I can think to suggest is to turn off the ‘show in drop down’ option for those pieces of reusable content and instead get people to choose them from the ‘see more choices’ dialog, so they still get some type of preview and it works with your fixed width layout. An unfortunate bug that makes little sense. Sorry it’s not a more comprehensive solution, if I come across a fix, I’ll post an update!

          • Mark Pitts

            I wrote a powershell script to disable ’show in drop down’. After running the script, I verified that this property was successfully updated. However, when I use the ‘reusable content menu, the items are still appearing. This seems to be a bug in SharePoint 2010.

  • Rommel Sison

    I’ve been searching for a comprehensive solution just like this! Thank you for the time you put into posting it.

    I have run into a problem though. Am I understanding correctly that the javascript will push the entire page down, so that when the Ribbon expands it will not cover up & hide the top of the page? If so, it seems that it’s not working for me.

    I tried referencing the javascript externally, adding it to the master page, and even inside a Content Editor Web Part. No luck.

    Any help would be very much appreciated. Thanks!

  • Rommel Sison

    I realize now that the javascript does work on my masterpage, however not as desired. It does display the page below the ribbon, but starts at – and shows – the status bar. So it does not display the banner or navigation bar.

    Why doesn’t it recognize the height of the div whose id is “s4-titlerow”? Any advice would be greatly appreciated.

    • http://www.webpoint0.com Ben

      Hi Rommel,

      The hiding of the title row when the ribbon is expanded in sharepoint 2010 is by design. It functions as the ‘browse’ tab’s contents, and so is hidden when another tab is chosen. You can turn it off though, so it always shows everything, if that is what you are trying to achieve? Let me know if so and I can tell you a quick way of doing it.

  • Abarco

    I keep getting a javascript runtime error on this statement:

    $(document).ready(function () {
    setInterval(setTopPos, 300);
    });

    Any way to fix this

    • http://www.webpoint0.com web.0

      Hi,

      Is there any description that you get with the error? The only reason I can see this failing here is if you don’t have jQuery loaded already or the setTopPos function loaded yet, are they definitely both in there before this statement as described in the post?

  • http://www.tonyishere.co.uk Tony_is_here

    This is a very useful article, everyone is trying to create a base masterpage from v4 rather than the adventure works example. I have created a master page using a wrapper inside s4-workspace. I wondered if you had come across the problem of large content not stretching the wrapper in IE7? When large content is on the page in IE7, the overflowing content is hidden rather than stretching the wrapper container. Have you tested this solution in IE7 as I expect the same issue to occur in your solution?

    • http://www.webpoint0.com web.0

      Hi Tony,
      Glad you like the article. In answer to your question the solution has been tested in IE7, but not for the specific circumstance you describe. I imagine that the issue you mention could be fixed using some conditional CSS perhaps to act differently for that particular browser and allow the wrapper to be stretched by the content?

      • http://profiles.google.com/nerudomregi nerudo mregi

        I also am having that very same issue. I would be glad if you could help. When I try to add a web part to the page the web part customisation panel that usually sticks to the right of the page is cut off or rather I should say it shows below the page(hiden under). A fix would be to strecth one of the containers I just dont know which one since Im just a Dev with less CSS kUNG fU

  • Pingback: SharePoint 2010 on the iPad, fixing one finger scrolling | web.0 | web development and design services – (x)html, css, javascript, jQuery, SharePoint 2010 / 2007, Magento, Wordpress, Joomla, Drupal, CakePHP, php, databases

  • Anonymous

    The problem I’ve experienced in the past with this is that the default SharePoint pop-up doesn’t turn up in the correct location when you’re already scrolled down on the page.

    • http://www.webpoint0.com web.0

      Hi,
      I’ve had a look at the situation you mention and can only recreate it with the check in dialog box. You could add this class to the setTopPos function to manage it in the same way as we do with the drop down menus. The class I found was ‘.ms-dlgContent’, so you could change the selector for the setTopPos to $(‘.ms-cui-menu, .ms-cui-tooltip, .ms-dlgContent’). Does that help with your issue?

      • Alan Coulter

        if you add the .ms-dlgContent option, then any dialogs that get launched via SP.UI.ModalDialog.showModalDialog will not show up properly.

        • http://www.webpoint0.com web.0

          Hi Alan,
          Sorry to hear that. Can you explain a little more what you mean by not show up properly, and give an example we could check please?

          • Alan Coulter

            In my case I had the main page appear grey as you would normally get a for a dialog window, but the actual dialog didn’t appear.

  • Tim

    I have had a go at this, however it seems to fail with no scrollbars being presnet at all on all browsers if you wrap the ribbon in a security trimmed control and then log on with only view rights.

    • http://www.webpoint0.com web.0

      Hi Tim,
      I have tested this in IE, Firefox and Chrome this morning and I can see the scrollbar in all of them, when logged in as a member of the visitors group. Is this the group you are using? Also, what settings are you using for your security trimmed control? If you send over the details I can stick them in our dev environment and see if I can recreate what you are seeing. The CSS shouldn’t care particularly about the presence of the ribbon so it should work fine in principle.

  • Pingback: Software Design » A Better Enhanced SharePoint 2010 Floating Ribbon

  • Pingback: A Better Enhanced SharePoint 2010 Floating Ribbon | Software

  • Archive

    Prev Next2012
    • Jan
    • Feb
    • Mar
    • Apr
    • May
    • Jun
    • Jul
    • Aug
    • Sep
    • Oct
    • Nov
    • Dec
  • Tweet
  • Categories

    • SharePoint design and development
    • Magento design and development
    • Javascript, AJAX and jQuery
    • Themes, skins and front ends
    • Custom web development solutions
    • General

all original content © copyright 2011 web.0. all rights reserved.