The default SharePoint 2013 master page, seattle.master
, expands to fill the browser window. In this recipe, we will modify the seattle.master
master page to have a fixed width using CSS.
Follow these steps to create a fixed width master page:
seattle.master
(for our example, we have renamed it Seattle_FixedWidth.master
).Seattle_FixedWidth.master
master page.Seattle_FixedWidth.master
master page.<head>
element.FixedWidth.css
file we will create.<SharePoint:CssRegistration ID="customCssRegistration" Name="<% $SPUrl:~Site/_catalogs/masterpage/resources/FixedWidth.css %>" runat="server"></SharePoint:CssRegistration>
FixedWidth.css
.FixedWidth.css
file using the Check Out option.FixedWidth.css
file.#s4-workspace
element using the following lines of code:#s4-workspace { background: #999999; }
#s4-titlerow
and #contentRow
elements a white background, a fixed width of 1024px
, and set the left-hand side and right-hand side margins to automatically center align the elements.#s4-titlerow, #contentRow { background: #FFFFFF; width: 1024px; margin-left: auto; margin-right: auto; }
#s4-titlerow
element to separate it from the header controls on the page:#s4-titlerow { margin-top: 50px; }
The page content for SharePoint pages is rendered within the s4-workspace DIV
element. In our recipe, we used CSS to provide a grey background color for s4-workspace
. We then used CSS to center align the content of the s4-workspace
element in a white box with a fixed width. An HTML element that has its left and right margins set to auto
will be centered in the element that contains it.
The #s4-workspace DIV
element is used by SharePoint to contain the majority of the page content. The #s4-titlerow DIV
element is used to contain the site logo, navigation, and search box in default configurations. The #contentRow DIV
element is used to contain the quick launch navigation and page content.
18.221.66.185