8

I created a master page and custom CSS file to brand the root site of on my SP10 server. I then applied this master page to all subsites. The style is applied properly on all sites except when I click the "All Site Content" link from one of the subsites. In this case, it still uses my master page but fails to apply the CSS.

The master page files links to the CSS with ../..Style Library/My.css (as inserted by SPD). This normally resolves properly to domain/Style Library/My.css but from the "All Site Content" (and possibly other undiscovered pages) it is trying to load domain/_subsite_/Style Library/My.css

How can I fix this?

2 Answers 2

6

You can try using <SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/My.css %>" After="corev4.css" runat="server"/> to resolve a full path in the masterpage, though I have a funny feeling that might only work in Publishing Pages...

8
  • It works for all site templates if the css file is accessable by specified URL.
    – Alexander
    Nov 29, 2011 at 20:07
  • 1
    But does it work in Foundation? Think that's what I should've said :P
    – James Love
    Nov 29, 2011 at 20:09
  • The CssRegistration is a part of SharePoint Foundation 2010 Class Libraries. Thus I think it works on it :P
    – Alexander
    Nov 29, 2011 at 20:22
  • 1
    Yeah CssReg is, but I'm on about $SPUrl, I'm sure I've seen that break in Foundation...
    – James Love
    Nov 29, 2011 at 20:24
  • 1
    Do note, however, that the <% $SPUrl token will not resolve in SharePoint Foundation (SPF). In SPF, you will need to specify the location using a hard coded URL. Unfortunately this will be limiting if you want to use different CSS files for different languages (since you won’t have a ~language token). (Source). I like SharePoint !
    – Alexander
    Nov 29, 2011 at 20:32
3

I have experienced this issue a few times and I always end up doing the same thing whenever the issue occurs to me. I simply put the CSS file in the layouts folder under 14 hive.

*Program files\Common files\Microsoft Shared\Web Server Extension\14\TEMPLATE\LAYOUTS*

From here all your sites, being root or sub, can reach it.

Both <SharePoint:CssRegistration name="/_layouts/My.css" After="corec4.css" runat="server"/> and <link rel="stylesheet" href="/_layouts/My.css" /> works this way.

Style Library works too, but can be tricky. If you use Style Library to store your CSS files, try putting %20 in between Style%20Library. Like so:

<SharePoint:CssRegistration name="$SPUrl:~sitecollection/Style%20Library/My.css" After="corec4.css" runat="server"/>

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.