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:

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:

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.

“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.

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.

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 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.