当我运行我的网站时,缺少母版页背景

时间:2010-11-13 09:19:58

标签: asp.net asp.net-3.5

我有一个带有背景和3列布局的母版页。起始页“default.aspx”是一个内容Web表单,并链接到母版页。在设计时,一切看起来都很棒,但在运行时,母版页背景是不可见的。它消失了。

如何解决这个问题?

**编辑**

母版页码表

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Live</title>
    <link rel="Stylesheet" type="text/css" href="../Stylesheets/MasterStyleSheet.css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="masterform" runat="server">
    <div id="divBanner" class="BannerDiv"></div>
    <div id="divMain" class="MainDiv">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            <div id="divMasterContent" class="MainContentDiv">
            <div id="divMainSideBar1" class="MainSideBar1Div" style="margin-left: 610px;"></div>
            <div id="divMainSideBar2" class="MainSideBar2Div" style="margin-left: 811px;"></div>
            </div>

        </asp:ContentPlaceHolder>
    </div>
    <div id="divFooterMenu" class="FooterMenuDiv"></div>
    </form>
</body>
</html>

样式表代码

body
{
    padding-left: 100px;
    background-image: url("../../App_LocalResources/wood.jpg");
    width: 1000px;
}

.BannerDiv
{
    border: thin solid Brown;
    padding-left: 50px;     padding-right: 50px;
    background-color: White;
    height: 150px; width: 895px;
}

.MainDiv
{
    padding-top: 10px;

    height: 600px; width: 1000px; 
}

.MainContentDiv
{
    background-color: White;
    border: thin solid Brown;
    height: 600px; width: 600px;
}

.MainSideBar1Div
{
    padding-left: 10px;
    position: relative;
    background-color: White;
    border: thin solid Brown;
    height: 600px; width: 170px;
    top: -2px;
}

.MainSideBar2Div
{
    padding-left: 10px;
    position: relative;
    background-color: White;
    border: thin solid Brown;
    height: 600px; width: 170px;
    top: -605px;
}

.FooterMenuDiv
{
    border: thin solid White;
    height: 30px; width: 997px;
    background-color: Gray;
    padding-top: 10px;
}

目前我在本地机器上运行它。

5 个答案:

答案 0 :(得分:1)

加载页面后,单击“查看源”以查看其呈现的背景图像的确切路径。

另一个选项:要检查css中提到的路径是否正确且可访问,请将其替换为母版页中head标签的内联背景设置。如果有效,则路径不正确。

答案 1 :(得分:1)

在发布网站时,您确定App_Localresources是否已添加到输出目录中?右键单击解决方案资源管理器中的wood.jpg,然后检查“构建选项”是否设置为“内容”。

http://msdn.microsoft.com/en-us/library/0c6xyb66(VS.80).aspx

顺便说一句......如果您的母版页和内容页位于不同的文件夹中,我建议使用站点根相对路径而不是相对路径:

http://msdn.microsoft.com/en-us/library/ms178116.aspx

答案 2 :(得分:1)

App_LocalResources是受保护的文件夹,asp.net不会让图像被重命名。

将您的背景图片和其他图片放在其他文件夹中,例如/ images /

验证只是尝试查看文件夹...-&gt; www.yoursite.com/App_LocalResources /

答案 3 :(得分:1)

我相信你已经放置了MasterPage&amp; Default.aspx在不同的文件夹位置。尝试将它们放在同一水平,看看差异。

由于样式表路径在运行时根据网页在设计时根据主页面进行考虑。

您可以使用的Ohter解决方案是 用

替换此行
<link rel="Stylesheet" type="text/css" href="../Stylesheets/MasterStyleSheet.css" />

这个新的

<link rel="Stylesheet" type="text/css" href="Stylesheets/MasterStyleSheet.css" />

我希望这能解决您的问题。

答案 4 :(得分:0)

我认为您需要确保服务器可以正确读取您的BG路径,因为您可以在本地PC上查看它,但是当在服务器上运行时,路径可能不是相对的,甚至图像也不是上传到目录

相关问题