Wednesday, December 5, 2012

Begin Styling Sharepoint 2010 CSS


Cascades are the way the web runs right now. Good sites set some good styles up at the top, then they inherit them. This is a system that works because it means no-one has to duplicate work, or eradicate inline code in order to change the colour of a link. The ways to do this are well documented at respectable institutions like A List Apart. You probably have a library of handy CSS references around, which you use to remind yourself how to build kicky styles that are consistent across your content-style-format separated software.
  1. Please gather those links, efficiently organized, into a pile.
  2. Import them into Microsoft Word, where they will be filled with <span> tags.
  3. Print them on the printer you have stolen from your client's network because you don't own a printer.
  4. Take them outdoors.
  5. Place them in a metal bin.
  6. Light them on fire, they're of no use here and will only pain you as you attempt to fix the Microsoft tradition of styling <em>every single element by individual and inherited class name</em>.
Today we are building your root-level styling sheet.

Today's Assumptions:
Styling Basic Master Pages in Sharepoint 2010
  1. Open Sharepoint Designer
  2. Open Notepad++
    1. Create a new file with whatever normal resets you use, and name it yourclient.css
    2. Save it in your normal local working files.
  3. Open Internet Explorer, and navigate to your sharepoint installation.
    1. Click on "Site Actions"
    2. View All Site Content
    3. Halfway down, there will be a Style Library folder.
  4. Open Style Library in Internet Explorer.
  5. Upload your CSS to the Style Library.
  6. In Sharepoint Designer, click on the All Files folder.
    1. It may not load on your first try, so click something else - Subsites maybe - then click back.
    2. Event handlers not passing is a common problem in everything to do with Sharepoint.
  7. Skip almost every folder and browse down to Style Library.
  8. Is your CSS showing up there? Good, you uploaded it correctly.
  9. Open your master page, remember, the default one you made on Monday.
This is the string of code you're going to need:
<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/[YOURCSSSHEET].css %>" After="corev4.css" runat="server"/>

I like to put it in immediately after the <title> tag. Let's break down what's going on in this tag, because it might be the first and only hint you have as to what language Sharepoint is expecting in its inline code.

SharePoint:CssRegistrationSharepoint likes you to register things with it before calling them. On the server side, it appears to be running through a bucket of mixed languages, and this is how it sorts things out. You need to register all kinds of things, but Sharepoint specific things require Sharepoint specific tags.

<% $SPUrl:~sitecollection/Style Library/[YOURCSSSHEET].css %>This is some inline code (I know how much you lurve it). This code identifies itself as being part of the ASP family by its use of the percentage sign to open tags. This might be relevant to you if you have never read ASP code before, as I had not done before someone gave me ill-advisedly high permissions on their underdeveloped extranet site.
Side Tip: Learning on the job is expected, because you are an underemployed and broke contractor. Find someone lazy and steal their permissions.
Pro Tip: Sharepoint pages can be written in any of three or four languages. You can figure out which language is expected at the very top of your master page, in the tag <%@Master language=""%>. Most Sharepoint 2010 builds are in C#.
After="corev4.css" runat="server"This is the money shot. Sharepoint 2010 does not cascade properly, and therefore, you must specify that your sheet comes after corev4.css, the default Sharepoint master sheet. You must. Or it will not load, it will not cascade, and it will be overwritten.

Do not bother separating your stylesheetsSharepoint 2010 specifically names inheritance structures, commonly using the !important tag to set your fonts and things permanently, which is a huge pain in the ass even before you try to get everything to import in order after corev4.css. Here is a sample inheritance structure, designed to make the Quicklaunch (left navigation panel) turn orange:

.s4-ql UL.root UL > LI > A.

This is the sort of language you are dealing with. Abandon all standards, ye who enter here.

No comments:

Post a Comment