简体   繁体   中英

Html Background Image not showing

Im making a website in Visual Studios. Im trying to change the Background of my website. When i add the image in Visual Studios it changes but when i launch it to see it in a web browser the background image is gone.

'<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
    .auto-style1 {
        width: 100%;
    }
    h1{
       text-align:center;
       font-family:Andalus;
       color:white;

   }
  body{
      background-image: url('C:\Users\........\Desktop\wood.jpg');
      text-align:center;
  }

    .auto-style2 {
        width: 664px;
    }
    p{
        font-family:Cambria;
        color:white;
    }

</style>
</head>
<body>

<form id="form1" runat="server">
<div>
<h1> Welcome</h1> 
  </div>
    <table class="auto-style1">
        <tr>
            <td class="auto-style2"><p>Username</p></td>
            <td class="auto-style2"><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </td>
            <td class="auto-style2">&nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="auto-style2">
                <p>Password</p></td>
            <td class="auto-style2">
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </td>
            <td class="auto-style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="auto-style2">
                &nbsp;</td>
            <td class="auto-style2">
                <asp:Button ID="Login" runat="server" OnClick="Login_Click" Text="Log in " />
                </td>
            <td class="auto-style2">
                &nbsp;</td>
            <td>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Log in as guest" />
            </td>
        </tr>
    </table>
    <asp:Label ID="Label1"  runat="server"></asp:Label>
</form>

It sounds like you haven't set up a project folder if you're referring to an image on your desktop. You're also using absolute values in the code so depending on how you upload your site this may cause issues. I'm not familiar with how Visual Studio's uploads the content.

Create a new project folder and then a sub-folder called images or something, and refer to them by like this:

  body{
      background-image: url('/images/wood.jpg');
      text-align:center;
  }

Have a look here: http://www.w3schools.com/html/html_images.asp for some more tips.

If you still have issues, paste the code here by viewing the source from your browser rather than the program, might give some idea of where it's going wrong.

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