In my MVC application, I refered a CSS file to render a background image for the page. I tried with all types of possibilities such as
background: url(../Images/login-box-backg.png) no-repeat left top;
background: url(../../Images/login-box-backg.png) no-repeat left top;
background: url(~/Images/login-box-backg.png) no-repeat left top;
background: url(./Images/login-box-backg.png) no-repeat left top; works only in Firefox
background: url(/Images/login-box-backg.png) no-repeat left top;
background-image: url(/Images/login-box-backg.png) no-repeat left top;
background-image: url(../Images/login-box-backg.png) no-repeat left top;
background-image: url(../../Images/login-box-backg.png) no-repeat left top;
background-image: url(~/Images/login-box-backg.png) no-repeat left top;
background-image: url(./Images/login-box-backg.png) no-repeat left top;
But It shows failed to load the given url and network error 404 in both Firefox and IE9.
CSS file * login-box.css *
#login-box {
width:333px;
height: 352px;
padding: 58px 76px 0 76px;
color: #ebebeb;
font: 12px Arial, Helvetica, sans-serif;
background: url(../Images/login-box-backg.png) no-repeat left top;
}
.reg_body
{
background-image: url(../Images/plain-blue-background-images-7117.jpg);
}
The style reference in my View as
<link href="@Url.Content("~/CSS/login-box.css")" rel="stylesheet" type="text/css" />
Which is the correct format to render background image from CSS file to MVC View.
I wonder why it doesnt accept anyformat when hosted in IIS.
Any suggestions.
Dont give this type of URL
background-image: url(../Images/plain-blue-background-images-7117.jpg);
use this one
background-image: url(/Images/plain-blue-background-images-7117.jpg);
if its not work...then try to remove slash /Images/ to Images/
Move your Images
folder to the Content
folder, and use this in your CSS:
background-image: url(Images/login-box-backg.png) no-repeat left top;
Your folder structure should look like this:
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.