Switching your SharePoint site from a fluid width (how it is setup out-of-the-box with v4.master or nightandday.master) is a simple task. It requires one change to the master page and the addition of one style statement. Where things get tricky is how to go from there in regards to handling the scroll bar SharePoint automatically generates under the docked ribbon. But let’s get the easy part done first.
First you need to add a CSS class to a very important DIV element in the master page file.
- Open your master page and search for s4-workspace. Add a CSS class of s4-nosetwidth. Your code should look like this:
<div id="s4-workspace" class="s4-nosetwidth">
- Next open the CSS file your site is using. Alternatively you can add a STYLE block in the HEAD element of the master page file. I prefer to use an external style sheet file whenever you can though.
- Add the following style statement to your CSS file:
body > form > div[id^="s4"] { width: 960px; /* Fixed width value */ margin: 0 auto; /* Centers contents on web page */ } - Save your CSS file and master page file and check out your changes in the browser.
If this does what you need, well you can be on your merry way.
If you are pleased with the fixed width but are perplexed by your new “floating” vertical scroll bar, please read on…
A little background
The s4-workspace DIV container along with some jazzy SharePoint script help create the ribbon and the ribbon placement. When you are editing your page content you will always want to have the edit controls viewable. When you scroll a long SharePoint page, the ribbon stays firmly in place at the top of your web page. This is referred to as a docked ribbon. In order to make this magic happen, SharePoint disables the browser’s scroll feature. If you look in the BODY element of the master page, you will see this:
<body scroll="no"...
Since the browser is no longer providing a scroll, SharePoint steps in and creates one, starting conveniently under the ribbon. This is all well and good as long as you are using a fluid width design. Once you switch to a fixed width, things can look a little weird:
So where do you go from here? Well there isn’t a straight forward answer as it all depends on your custom design, site requirements and the preferences of your team and site users. As with anything that has to do with SharePoint, you have options.
Understanding the CSS style statement
Before looking at some options, let’s stop really quick to look at the style statement that was used before and understand what it is doing.
body > form > div[id^="s4"] {
width: 960px; /* Fixed width value */
margin: 0 auto; /* Centers contents on web page */
}
body > form > div[id^="s4"]
In layman’s terms, this selector is saying…
Apply this style to any DIV element with an ID that starts with “s4″ that is a child of the FORM element that is a child of the BODY element.
width: 960px;
This is your desired page width. I used 960px because it is a very commonly used fixed width value.
margin: 0 auto;
The top and bottom margin is being set to zero pixels, and the left and right margins are being automatically calculated based on the width of the element and the width of the browser. The “auto” is what centers the content on the page.
Got it. Let’s move on.
Now that we understand what the CSS style statement is doing, we can alter it in different ways to create various solutions for our floating vertical scroll bar.
Option 1: Add some distinction between the scrollbar and the background to make it look like a part of your intended design
Add border properties to the style statement to define the edges and add a style statement for the background to add some color and stop the white on white look it has by default.
body > form > div[id^="s4"] {
width: 960px; /* Fixed width value */
margin: 0 auto; /* Centers contents on web page */
border: solid black; /* Border style and color */
border-width: 0 1px; /* Zero border top and bottom and 1 pixel border left and right */
}
#s4-workspace {
background: white; /* Content background color */
}
body {
background: gray; /* Background color */
}
The end result:
Option 2: Keep the ribbon on a dark background that stretches across the page; keep the scroll bar on the far right of the browser window; set everything else to centered fixed width
Alter the style statement selector to match the following. You also need some additional style statements to correct some visual issues that crop up.
#s4-bodyContainer,
#Ribbon {
width: 960px; /* Fixed width value */
margin: 0 auto; /* Centers contents on web page */
}
#RibbonContainer {
background: #21374C; /* Set background of expanded ribbon area */
margin-left: -11px; /* Correct ribbon placement to properly align with content that has the vertical scroll bar */
}
.ms-cui-topBar2 {
border-bottom: 1px solid transparent; /* Correct ribbon border issue */
}
The end result:
Option 3: Combine 1 & 2
Use parts of option 1 & 2 to keep the stretched ribbon background and right scrollbar, but also provide some visual definition for the centered content.
#s4-bodyContainer,
#Ribbon {
width: 960px; /* Fixed width value */
margin: 0 auto; /* Centers contents on web page */
}
#s4-bodyContainer > div {
border: solid black; /* Border style and color */
border-width: 0 1px; /* Zero border top and bottom and 1 pixel border left and right */
}
#RibbonContainer {
background: #21374C; /* Set background of expanded ribbon area */
margin-left: -11px; /* Correct ribbon placement to properly align with content that has the vertical scroll bar */
}
.ms-cui-topBar2 {
border-bottom: 1px solid transparent; /* Correct ribbon border issue */
}
#s4-statusbarcontainer {
width: 100%; /* Correct width for status bar to properly align borders */
}
body {
background: gray; /* Background color */
}
The end result:
The last two options that keep the ribbon stretched across the page work great as long as your ribbon bar is a contrasting color from the page background. Once you start using the same color, things go back to looking weird:
I don’t have a handy solution for this yet because with this issue I believe we are moving past what CSS can patch up and accomplish.
One thing I have not mentioned is undocking the ribbon. It is possible and simple to do, but it has some bugs that can create a large impact on your sites, especially your event calendars. I have moved away from undocking the ribbon until a new solution is available, and I just happen to know a certain developer named Dustin Miller who is working on one. ;)
Thanks to SharePoint Experience alum Jed for the blog post inspiration!





Creating a centered fixed width design in SharePoint 2010 http://t.co/k3VepIXR
RT @speheather: Creating a centered fixed width design in SharePoint 2010 http://t.co/8bikmppW – Great post Heather!!
“@speheather: Creating a centered fixed width design in SharePoint 2010 http://t.co/ZdoyE8tw” <- great summary.
“@speheather: Creating a centered fixed width design in SharePoint 2010 http://t.co/nIt5emPp” great work on putting this together!
Again, I’m glad you’re back to blogging. I like this method as an alternate to the undocked ribbon. Is the issue with the undocked ribbon specific to the calendar? I ask, because I imagine lot of cases where fixed width design are applied may get away with out using the calendar. I’m thinking public sites, mostly won’t.
Once you undock the ribbon you affect the math that SharePoint does for placement of certain elements that are generated on the fly. So for example when you click on a time slot in the calendar in day view, the select color and Add button appear several time slots above where you clicked. It doesn’t have anything to do with fixed width, it is undocking the ribbon that causes the issues. The two main places I have seen problems are the Calendar and Gantt chart.
Creating a centered fixed width design in SharePoint 2010 http://blog.sharepointexperience.com/2012/04/03/creating-centered-fixed-width-design-sharepoint-2010/
estupendo, apenas estoy empezando a desarrollar en sharepoint y casi no podía modificar con esa libertad…pero llegaron ustedes y me brindaron ese conocimiento…muchas gracias…desde Colombia.
Glad your posting again Heather. And now for the question –
The issue I’m having is that content placed in web part zones spills out over into the side bars of the fixed-width region, leaving a real “ugly” look to the page. I’ve tried applying a few of the jQuery solutions I’ve found online to adjust the “fixed” portion of the page to accommodate for this, (kind of making what I like to call a floating-fixed-width master page). Any suggestions for how to deal with this?
Have you added class=”s4-nosetwidth” to the s4-workspace div in the master page?
Anyone know where I can get info about changing Font Size for All Day Calendar entries in SP2010?
I found info for previous version of SP using CSS, but nothing for 2010. Thank you!!!
Have you tried this?
.ms-acal-item {
font-family: times New Roman;
}
[...] Creating a centered fixed width design in SharePoint 2010 Switching your SharePoint site from a fluid width (how it is setup out-of-the-box with v4.master or nightandday.master) is a simple task. It requires one change to the master page and the addition of one style statement. Where things get tricky … Read More… [...]
[...] page and CSS to a centered, fixed width design. For instructions on how to do this, check out my Creating a centered fixed width design in SharePoint 2010 blog post. A lot of designs like to use “960px” for the width value. Unfortunately [...]
I have implemented fixed width that expands with content, and it works on most page layouts/types. However, when a user creates certain pages (i.e. a publishing Blank Web Part page) the fixed width does not expand with the contents of the page, causing the web part contents to go outside the border. I have used the class=”s4-nosetwidth” to the s4-workspace div already. Is there a way to get around that issue?
I can’t duplicate this issue. Can you please send me a screenshot? You can use this form to send it: http://blog.sharepointexperience.com/csschallenge/