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 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.

share|improve this question
add comment

4 Answers 4

up vote 1 down vote accepted

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.

share|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 Sep 5 '12 at 12:17
add comment

Try using:

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

worked for me.

share|improve this answer
    
Somehow, this doen't work for me. –  Nadeem Yousuf Sep 5 '12 at 11:21
add comment

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?

share|improve this answer
add comment

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 :)

share|improve this answer
2  
PublishingImages is not a folder in in 14 hive. It is a an images libraray. –  Nadeem Yousuf 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 Sharepoint 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 Sep 5 '12 at 10:24
add comment

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.