I have a css class which applies an image to the div tags throughout the application. The css class is defined in a separate css file located in SharePoint styles folder in the 14 hive.

.logo {
    background: url("/_layouts/images/logo.png") no-repeat; 
    width: 172px; 
    height: 36px; 
    margin-top: 23px; 

But now we have decided to put the image in the images library named PublishingImages. Following is the url of the image in the library. htt://server/PublishingImages/logo.png I tried to change the background property to url("~/PublishingImages/logo.png") no-repeat; But that doesn't work. Note: The css file still exists in 14 hive.


The tilde only works for controls that can run at the server. For example, if you have an image control, you can set the source to "~/folder/file" in addition to having runat="server" in the tag. Therefore, you cannot use the tilde in stylesheets - CSS is something that the client's browser handles. The best thing to do is use the full path for the image.

| improve this answer | |
  • Yes, I realized that and added an asp image control to get things working. <asp:Image ID="Image1" ImageUrl="<% $SPUrl:~Site/PublishingImages/logo.png %>" runat="server" /> – Nadeem Yousuf-AIS Sep 5 '12 at 12:17

Try using:

background: url("/PublishingImages/logo.png") no-repeat;

worked for me.

| improve this answer | |

In CSS, the background URL is either absolute or relative to the stylesheet location - in your case it means the folder in the 14 hive.

You might need to reconsider moving the image away from the stylesheet - maybe you'll also need to put the stylesheet in a library?

| improve this answer | |

I dont know if this will work for you but worth a try! if the folder is new then have you made sure on your hive folder goto the folder PublishingImages, right click and check your security settings are all correct, Also if you can see two checkboxes at the bottom... the first should be checked and the second not checked. Click on the second checkbox to reset the inheritance. Performe this for the image aswell.

Hope it helps :)

| improve this answer | |
  • 2
    PublishingImages is not a folder in in 14 hive. It is a an images libraray. – Nadeem Yousuf-AIS Sep 5 '12 at 9:17
  • sorry was confused! have you tried using the full url? when you go to the image library, right click on the image and select copy shortcut and paste it into the url – Ali Jafer Sep 5 '12 at 9:59
  • Yes, I tried full url and it is working perfectly fine with that. But I can't hardcode url with server name, I have to use relative url. – Nadeem Yousuf-AIS Sep 5 '12 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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