Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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
share|improve this answer
    
I'll give that a try vgrem, thanks :) –  IrishChieftain Oct 15 '12 at 18:58
    
irishchieftain let me know please if it doesn't help –  Vadim Gremyachev Oct 17 '12 at 12:35
    
Thanks, that worked perfectly :-) –  IrishChieftain Oct 19 '12 at 15:36
    
I'm glad it helped :-) –  Vadim Gremyachev Oct 19 '12 at 18:14

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"/>
share|improve this answer
    
Seb, I tried that with After="nightandday.css" and it has no effect. –  IrishChieftain Aug 30 '12 at 15:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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