(I'm using Visual Studio 2013) I want to set a background for my web page. if I put the
CSS
body {
background-image: url("Content/Images/back.png");
}
within my aspx file it will work and will set my desired background. however when I put in the css file it won't work
this is how css looks
body {
background-image: url("Content/Images/back.png");
}
I want to mention that I have attribute in the aspx and when I change the background color in css to test it it works . but for the background it won't work!!
here is my .aspx file ;
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="EmptyWebForm.Default" %>
<link href="Content/Styles/styles.css" rel="stylesheet" type="text/css" />
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<style type="text/css">
/*body {
background-image: url("Content/Images/back.png");
}*/
</style>
</div>
</form>
</body>
</html>
Probably your CSS file is in different directory. Url for image is relative to css file so you should change it to for example:
body {
background-image: url("../Content/Images/back.png");
}
You've added more code so the answer in that case will be:
body {
background-image: url("../Images/back.png");
}
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.