Elevate Your SharePoint Knowledge

General Information

This past year I was working on a large SharePoint 2010 Publishing Site project, when I encountered some issues with the Calendar web part.  The project was using heavy custom branding, and there was a lot of custom CSS being applied.  I hadn’t created the original custom branding for this project, I just inherited it. 

The issue I encountered was how the Calendar Event items were being displayed.  The Event Titles were being truncated and the colors were all wrong. 

Before I begin outlining the process of customizing the look and feel of the Calendar web part using CSS, I’d like to point out some useful information first. 

There are a couple of really good SharePoint 2010 branding books that I have read and I still reference.  Here are the books:

  • Professional SharePoint 2010 Branding and User Interface Design by Randy Drisgill, John Ross, Jacob J. Sanford, Paul Stubbs, Larry Riemann. 
  • Beginning SharePoint Designer 2010 by Woodrow W. Windischman, Asif Rehmani, Bryan Phillips, Marcy Kellar. 

I find it helpful to use some CSS tools.  I use the following add-ons and software tools for all my CSS coding in SharePoint 2010:

  1. There is an add-on for the Firefox browser called “Firebug”.  I used this add-on a lot when I’m creating SharePoint custom CSS.  It allows you to pick an element on a web page and then it will show you what CSS properties are being applied to the element and other other useful CSS information like the CSS class and which CSS file it is defined in.  Here is the link for “Firebug”http://getfirebug.com
  2. TopStyle” is a 3rd party CSS software tool.  This tool isn’t necessary, but it makes life much easier working with CSS files.  It has IntelliSense and it has a CSS Palette Editor that is great when you are working with hex values.  Here is a link to “TopStyle”:  http://www.topstyle4.com
  3. The other tool I use a lot when working with SharePoint custom branding, whether I’m creating custom master pages, custom page layouts, custom list, custom css files, etc.. I use “SharePoint 2010 Designer”.  The 32 bit version is far less buggy.  I learned this the hard way.  I use the 32 bit version of “SharePoint 2010 Designer” now.  “SharePoint 2010 Designer” is a free download from Microsoft.  Here is a link for “SharePoint 2010 Designer”http://www.microsoft.com/download/en/details.aspx?id=16573

steps Outlined:

  • Discover which CSS Classes and IDs are being used for the various Calendar items that you want to re-style.  I will use “Firebug” for this step.
  • Create the new CSS file.  I’ll use “TopStyle” for this step. 
  • Test the new custom CSS.  I’ll use “SharePoint 2010 Designer” for this step.
  • Apply the new CSS file(s) to our Publishing Site.  I’ll use “Internet Explorer” for this step. 

Discovering the CSS Classes and IDs

  • Open your Firefox browser and navigate to your Publishing SharePoint 2010 web site.
  • Navigate to your web page with the Calendar or navigate directly to the Calendar List. 
  • Click on the “Firebug” icon in the bottom right hand corner of your browser window:

Firebug

  • The “Firebug” window will appear at the bottom of the screen.  You should see something like this:

Firebug2

  • Click on the icon for Inspecting a page element.  It looks like this: FFInspectElement
  • Mouse over an element on the Calendar that you want to discover the CSS information about so it can be re-styled.  Now, click on the element.  You should something like this:

Firebug3

  • Here is the CSS information that I have changed for this element:

.ms-acal-sdiv .ms-acal-time {

color: #525252;

overflow: hidden;

white-space: nowrap;

width: 100px;

}

div.ms-acal-item, div.ms-acal-item div, div.ms-acal-item a:link, div.ms-acal-item a:visited, div.ms-acal-item a {

font-size: 6.5pt !important;

padding-bottom: 2px;

}

  • Once you have your CSS information, then you can create your new CSS file that you will add all your CSS Classes and IDs to with the new styles definitions/properties. 
  • Open up “TopStyles” and create a new CSS file.  I’m going to call my new CSS file:  CalendarUpdates.css
  • Next, I’ll add my newly discovered CSS information for the Calendar Event Title to the CalendarUpdates.css file. 
  • Modify the CSS so that it matches the new look and feel I desire. 

Testing the New Custom CSS for the Calendar

For testing the new CSS file, I’m going to assume that you are only using the out of the box (OOTB) CSS files for your Publishing site.  Meaning, you are either using the CoreV4.css and/or the Nightandday.css file, and that you are loading the OOTB CSS file(s) from your Master Page.  To see code examples of this, visit this link:  http://erikswenson.blogspot.com/2010/01/sharepoint-2010-css-references-in.html.

There are two approaches we could use for testing the new CSS for the calendar.  I could embed the CSS into our calendar aspx file or simply reference the new CSS file and make sure that it is the last CSS file that loads.  I’ll cover the latter approach. 

The first approach would be useful for Publishing Sites that are already in production and we don’t want our testing to affect the whole site and its users. 

Lets get started on testing the custom CSS code.

Importing Custom CSS file into SharePoint
  • Open up “SharePoint 2010 Designer”.
  • Navigate to the Styles Library folder (All Files/Styles Library).
  • Next, navigate to the en-us folder. 
  • Create a new folder here for you custom CSS file(s).  I created a folder called “CustomCSS”. 
  • Open up this new folder.
  • Click on the icon “Import Files” in the ribbon tool bar at the top.
  • Locate your new custom CSS file (for my example, it is called CalendarUpdates.css), then import the CSS file. 
  • Next, check in the file so it is visible and accessible to everyone.  To do this, click on the icon “Check In” in the ribbon tool bar.
  • Select the option “Publish Major Version” and click the “OK” button. 
    Using the New Custom CSS file
    • Open up “Internet Explorer”.
    • Navigate to your Publishing Site and login.
    • Select from the menu: Site Actions—>Site Settings—>.
    • Then under “Look and Feel” section, select the “Master Page” link. 
    • Under the “Alternate CSS URL” section, select the option: “Select a CSS to be used by this Publishing site and all sites that inherit from it”. 
    • Click on the browser button and navigate to:
    • Styles Library\en-us\customcss folder and select:  customupdates.css file, click the “OK” button.
    • Click the “OK” button again to save and apply the new Alternate CSS file settings.

    Note:  Since the OOTB CSS are loading from the Master Page, and our new custom CSS file (calendarupdates.css) is loading as the Alternate CSS file, our custom CSS will load last.  This is important.  We want to override the default settings (OOTB) for the Calendar Web Part, so we need to load our CSS last.  CSS styles cascade by nature.  Hence the name Cascade Style Sheet – CSS. 

    Testing New CSS for Calendar

    Navigate to your Calendar List, and see how your Calendar Events are now being displayed.  You can tweak your CSS using “SharePoint 2010 Designer” or “TopStyle”.  If you use “TopStyle”, then you have to re-import and re-check in the custom CSS file.  If you use “SharePoint 2010 Designer”, then you only need to check out and check in your custom CSS for testing purposes. 

    Follow

    Get every new post delivered to your Inbox.