0

I'm branding a SharePoint 2010 publishing site. I'm deploying a custom master page and CSS style sheet using a Feature. I'm applying CSS as an alternate style sheet using the UI: Site Actions -> Site Settings -> Master Page, but my custom style sheet is not being applied last as I feel it should be:

<link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Themable/Core%20Styles/controls.css"/>
<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/search.css?rev=T%2Bhraxktc1A8EnaG5gGMHQ%3D%3D"/>
<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=iIikGkMuXBs8CWzKDAyjsQ%3D%3D"/>
<link rel="stylesheet" type="text/css" href="/Style%20Library/Custom.css"/>
<link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Themable/Core%20Styles/nightandday.css"/>

Is this a bug? With SharePoint 2007 it would have been applied last affording me the chance to override the built-in CSS.

2 Answers 2

1

If you place CSSRegistration for your custom css on first line and specify After property to corev4.css as shown in example below

<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style%20Library/Custom.css %>" After="corev4.css" runat="server"/>
<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Themable/Core Styles/controls.css %>" runat="server"/>
<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Themable/Core Styles/nightandday.css %>" After="corev4.css" runat="server"/>

then it will be rendered as you expected i suppose

<link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Themable/Core%20Styles/controls.css"/>
<link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Core%20Styles/page-layouts-21.css"/>
<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=iIikGkMuXBs8CWzKDAyjsQ%3D%3D"/>
<link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Themable/Core%20Styles/nightandday.css"/>
<link rel="stylesheet" type="text/css" href="/Style%20Library/Custom.css"/>

CssLink control responsible for ordering and rendering css files on page depends on several factors:

  1. Order of placing CSSRegistration control
  2. If parameter After specified
  3. If Alternate Css specified
2
  • irishchieftain let me know please if it doesn't help Oct 17, 2012 at 12:35
  • I'm glad it helped :-) Oct 19, 2012 at 18:14
0

I'm not a css expert but did you try to play with the after property?

<SharePoint:CSSRegistration Name="/Style Library/customfile2.css" After="customfile1.css" runat="server"/>
1
  • Seb, I tried that with After="nightandday.css" and it has no effect. Aug 30, 2012 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.