2

Here is my project directory where I have

style.css

under Content and

image.jpg

under Images

enter image description here

Login.aspx page is default page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="LoginDemo.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <link href="~/Content/style.css" rel="stylesheet" type="text/css" media="screen" runat="server" />

    <title>LOGIN</title>

</head>
<body>
</body>
</html>

And here is CSS

*{
    margin:0px;
    padding:0px;
}

body{
    background-image:url(Images/image.jpg);
    background-size:cover;
    background-attachment:fixed;
    font-family:Times New Roman ;
}

Page is loaded successfully but without loading background image. Please help me. I read different article and as per suggested solutions I do the same steps but still there is problem.

3
  • Have you try to clear cache or use with a fresh browser? Commented Oct 4, 2018 at 12:43
  • Why the runat="server"? usually that attribute implies some server side execution/processing and in the stylesheet it looks unnecesary (problematic since there is no handler configured in IIS for css extension). Commented Oct 4, 2018 at 12:47
  • @Sigma yes I clear the cache and use fresh browser. bradbury9 I read 1 article and there they suggest to use runat=server Commented Oct 4, 2018 at 12:49

3 Answers 3

3

Images is not in the Content folder. so in your css, you should go back a folder:

  background-image:url(../Images/image.jpg);

Note the ../ before Images folder in the path

Sign up to request clarification or add additional context in comments.

2 Comments

thanks dear now I understand. But 1 question why its not working when I use url(~/Images/image.jgp)
@SalmanMushtaq you are welcome. I'm not sure but i think ~/ has meaning in Asp.net and not css
2

put a single quote before and after your image path,and also use (..) to refer up directory, so correct your css code with these lines:

*{
    margin:0px;
    padding:0px;
}

body{
    background-image:url('../Images/image.jpg');
    background-size:cover;
    background-attachment:fixed;
    font-family:Times New Roman ;
}

and where is your webpage location ? is it in a directory ?

2 Comments

Thanks. But still I am confused why its not work when I used url(~/Images/image.jpg), Web pages located under project directory
@SalmanMushtaq your welcome Salman, i think css doesn't understand (~) character and also css files are located in a sub-directory which you should go up directory then addressing your own folder that image located.
0

Create an error in style.css file, compiler didn't listening the file. clean the solution and Rebuilt it again. Surely It will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.