如何让页脚贴在 asp.net 页面上?

How to make footer stick on asp.net page?

我在 asp.net 中有一个母版页,它将包含其他页面内容并抛出一个 ContentPlaceHolder。我想在母版页中有一个页脚,该页脚使用内容 css 无论页面中显示什么内容都使用内容 ContentPlaceHolder。

这是我的主页:

<body>
<form id="form1" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
    <Scripts>
        <asp:ScriptReference Path="Scripts/jquery-1.11.2.min.js" />
        <asp:ScriptReference Path="Scripts/CommonMethods.js" />
        <asp:ScriptReference Path="Scripts/CommonProperties.js" />
        <asp:ScriptReference Path="http://code.jquery.com/ui/1.10.4/jquery-ui.js" />
        <asp:ScriptReference Path="Scripts/jquery.watermark.min.js" />
    </Scripts>
</asp:ScriptManager>
<div id="header">
    <h1>
        SABIS® Educational Systems INC.
    </h1>
</div>
<div id="nav">
</div>
<div id="section">
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
    </asp:ContentPlaceHolder>
</div>
<div id="footer">
    Copyright © Sabis.net
</div>
<asp:ContentPlaceHolder ID="cpClientScript" runat="server">
</asp:ContentPlaceHolder>
</form>

我尝试了很多 css 但对我来说没有任何效果,总有一个流程!!

好的,我认为您首先混淆了一些东西:ASP 对浏览器显示您的页面的方式没有影响。那是因为 ASP 是一种输出纯 HTML 的服务器端语言。然后,此 HTML 连同任何 linked 到(CSS、JavaScript、图像...)的资产一起发送到您的浏览器。

这就是 CSS 的用武之地。CSS 用于向 HTML 添加样式。所以你是绝对正确的 CSS 是获得你描述的行为的方式。方法如下:

div#footer{ // Add the style below to the div with ID "footer"
    position: fixed; // Set the position to "fixed" to the screen
    bottom: 0px; // The fixed position should be 0px from the bottom of the screen
    width: 100%; // Optional, this stretches the div across the width of the screen
}

您可以将这段 CSS 放在页面 <head><style> 标记中,但通常最好将其放在单独的 .css 文件和 link 到它在页面的 <head> 中,像这样:

<link rel="stylesheet" href="path/to/stylesheet.css">

补充阅读:here's a getting started guide about CSS stylesheets.