繁体   English   中英

HTML背景图片未显示

[英]Html Background Image not showing

我在Visual Studios中制作了一个网站。 我试图改变我网站的背景。 当我在Visual Studios中添加图像时,它会更改,但是当我启动它以在Web浏览器中查看它时,背景图像就消失了。

'<!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>

如果您要引用桌面上的图像,听起来好像没有设置项目文件夹。 您还在代码中使用了绝对值,因此根据您上载网站的方式,这可能会导致问题。 我不熟悉Visual Studio上载内容的方式。

创建一个新的项目文件夹,然后创建一个名为images或诸如此类的子文件夹,并通过如下方式引用它们:

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

在这里查看: http//www.w3schools.com/html/html_images.asp,以获得更多提示。

如果仍然有问题,请通过从浏览器(而不是程序)查看源代码来将代码粘贴到此处,这可能会给您一些提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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