CSS Background-Image refuses to display in ASP.Net MVC

前端 未结 10 905
别那么骄傲
别那么骄傲 2020-12-10 01:14

I am having trouble displaying an background image in my ASP.NET MVC 2 application. Currently, In ~/Views/Shared/Site.master, I set my link to the style sheet to:

         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 01:55

    Keep it simple stupid.

    At all times, try to stick to relative paths with css url attribute.

    /* Assuming your Site.css is in the folder where "Images" folder is located */
    /* Your Css Image url */
    
    background-image: url("Images/YourImageUrl");
    

    The problem with wrong urls is that css can't locate that image as it doesn't understand the convention used on that url, hence the image is not displayed. So to keep it simple use the reigning relative path approach, and you'll never have problems.

提交回复
热议问题