Take the 2-minute tour ×

In my current project, I checked something that was already developed, and there is a webpart project item, which has embedded CSS on the HTML markup.

I dont like this way because the code does not look clean, and I think it would be easier to maintain if there is a separate css file in the 14 hive or something

The question is: 1. How to provision CSS files to the 14 hive? 2. Will those css be available to all site collections? 3. I suppose that I would need to change the master page to be available to use the CSS classes in the webparts.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

There's two ways to do this:

  1. store your css file in the style library (css can be different for eacht site collection.

To do so: Use a module

   <Module Name="Test" Url="Style Library/CSS Style Sheets" Path="" RootWebOnly="FALSE">
     <File Url="Test.css" Type="GhostableInLibrary"/>

More info: http://msdn.microsoft.com/en-us/library/gg447066.aspx

  1. store your css in the 14/_layouts folder (css will be the same for all site collections)

To do so: add a mapped folder (layouts) in your Visual Studio 2010 solution and add the css file in a subfolder of this folder. This will be provisioned on deployment without feature or so.

more info: http://msdn.microsoft.com/en-us/library/ee231521.aspx

  1. You will, indeed, need to change your masterpage by adding this line:

http://pastie.org/3379314 (could not paste it here, dont know why)

BTW, the above explanation also works for jquery files etc...

share|improve this answer
FYI - if you paste code in here, select it and click the { } symbol in the toolbar, it'll apply formatting so it renders when you post. –  James Love Feb 14 '12 at 8:50
As you can see, ive done this in my first line of code. But the second line (the one i've put on pastie) did not work. It removed 50% of the code :| –  Frederik P. Feb 14 '12 at 9:14
Why the hell does he change my numbered list ??? It's supposed to be 1, 2, 3 :( –  Frederik P. Feb 14 '12 at 11:37
Lol, bit buggy at times, is the text editor :P –  James Love Feb 14 '12 at 13:22
add comment

Your Answer


