将背景图片添加到asp.net主网页asp.net 4.0和html5

时间:2012-06-20 02:16:26

标签: c# html5 css3 background-image asp.net-4.0

使用ASP.NET,C#,HTML5和CSS3。我的MasterPage无法识别我在样式表中设置的背景图像。我从2009年在MSN开发人员的ASP.NET论坛上找到了答案,但它仍然没有用。检查代码后,答案与XHTML过渡相关,即Visual Studio中.NET的默认doctype。

有什么建议吗?提前谢谢。

<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>

    <link href="../changes.css" rel="stylesheet" type="text/css" />
    <link href="../style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>

    <form id="form1" runat="server">
    <div id="PageWrapper">


    html, body {
    background-color: #000;
    background-image: url('../images/darker_wood_1600x1200.jpg');
    background-attachment: scroll;
    background-repeat: repeat-x;
            }






    <!DOCTYPE html>
<html>
<meta charset="utf-8" />

<head><title>

</title>
<link href="changes.css" rel="stylesheet" type="text/css" /><link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>

    <form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRkM1MGX8QufJ31wnSeINevDB81G3lHsitto4ucLAdg6zs=" />
</div>

    <div id="PageWrapper">

    <div id="Header"><a href="./">Header here
        </a></div>

    <div id="MenuWrapper">Menu here</div>

    <div id="MainContent">


    </div>

    <div id="Sidebar">Sidebar here</div>
    <div id="Footer">Footer here</div>
    </div>

</form>

1 个答案:

答案 0 :(得分:1)

此代码适用于我,但我不知道上面的代码是否如何。因为您在div的中间发布了样式表值。

另外,如果页面无法读取文件。尝试使用其他文件或尝试更改文件的搜索路径。也许它无法读取它,因为它在服务器目录之外。因为CSS代码看起来是正确的。

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>

    <link href="../changes.css" rel="stylesheet" type="text/css" />
    <link href="../style.css" rel="stylesheet" type="text/css" />
    <link href="changes.css" rel="stylesheet" type="text/css" /><link href="style.css" rel="stylesheet" type="text/css" /></head>

    <meta charset="utf-8" />
    <style type="text/css">


        // If you want the "Page" background to be this way:
        html, body
        {
            background-color: #000;
            background-image: url('../images/darker_wood_1600x1200.jpg');
            background-attachment: scroll;
            background-repeat: repeat-x;
        }

        // Or the PageWrapper
        div#PageWrapper
        {
            background-color: #000;
            background-image: url('../images/darker_wood_1600x1200.jpg');
            background-attachment: scroll;
            background-repeat: repeat-x;
        }


    </style>
</head>
<body>
    <!--- <form id="form1" runat="server"> --->
    <form method="post" action="Default.aspx" id="form1">
        <div class="aspNetHidden">
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRkM1MGX8QufJ31wnSeINevDB81G3lHsitto4ucLAdg6zs=" />
        </div>
        <div id="PageWrapper">

            <div id="Header">
                <a href="./">Header here</a>
            </div>
            <div id="MenuWrapper">
                Menu here
            </div>

            <div id="MainContent">
            </div>

            <div id="Sidebar">
                Sidebar here
            </div>
            <div id="Footer">
                Footer here
            </div>
        </div>
    </form>
    <!--- </form> --->
</body>
</html>