简体   繁体   中英

how to set background-image

I am using asp.net MVC. In my application,To set the background image,I have implemented like,

 background-image:url("../../Images/Home/Logo.png");

When I debug this,background image is displaying ,when I deploy it to the server,It is not displaying . If I implement like

background-image:url("Images/Home/Logo.png");

background-image is displaying after deploying in the server but in my local it is not displaying,what is the solution for this?

You should use correct client relative path

aspxImgCtrl.ImageUrl = "~/Images/GIF/arrow.png"; 

The ~ operator is recognized by asp.net only for server controls and in server code. You cannot use the ~ operator for client elements.

Try

background:url('<%= ResolveClientUrl("~/path/to/img") %>');

Place cssImages in same place with css file. I mean

Root
    Content
        Site.css
        Images
            Logo.png

And use absolute path like this: background-image:url("Images/Logo.png"); in Site.css

I have encountered the same problem. This can be fixed by placing the image folder inside the same folder where your css files are

I hope you know the meaning of "../" Refer Here . If you know this you can fix the thing easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM