【问题标题】:Html Background Image not showingHtml背景图片不显示
【发布时间】:2015-04-14 12:25:14
【问题描述】:

我正在 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>

【问题讨论】:

  • 查看图片在background-image: url('C:\Users\........\Desktop\wood.jpg');中的路径
  • 我在 Visual Studio 的预览窗口中仔细检查了它,它显示但不在浏览器中这是我第一次使用 Visual Studios

标签: html image visual-studio background


【解决方案1】:

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

创建一个新的项目文件夹,然后创建一个名为 images 或其他东西的子文件夹,并通过以下方式引用它们:

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

查看这里:http://www.w3schools.com/html/html_images.asp 了解更多提示。

如果您仍然有问题,请通过从浏览器而不是程序查看源代码将代码粘贴到此处,这可能会让您了解问题出在哪里。

【讨论】:

  • 谢谢你看看
猜你喜欢
  • 2014-02-11
  • 2020-09-11
  • 1970-01-01
相关资源
最近更新 更多