【问题标题】:How to make footer stick on asp.net page?如何使页脚粘在asp.net页面上?
【发布时间】:2015-06-26 04:39:54
【问题描述】:

我在 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,但对我来说没有什么能正常工作,总是有一个流程!!。

【问题讨论】:

    标签: css asp.net master-pages sticky-footer


    【解决方案1】:

    好的,我认为您首先混淆了一些东西:ASP 对浏览器显示您的页面的方式没有影响。这是因为 ASP 是一种输出纯 HTML 的服务器端语言。然后,此 HTML 连同链接到的任何资产(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 放在页面的 &lt;head&gt; 中的 &lt;style&gt; 标记中,但通常最好将其放在单独的 .css 文件中并在页面的 &lt;head&gt; 中链接到它页面,像这样:

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

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

    【讨论】:

    • 感谢您的精彩介绍。我知道你说什么,但可能是我没有很好地解释自己,这仍然是我第一次接触网络。您提供的 css 以任何方式工作,就像我想要的那样。谢谢。
    猜你喜欢
    • 2023-04-01
    • 2013-09-26
    • 2011-05-06
    • 1970-01-01
    • 2011-06-30
    • 2017-08-24
    • 1970-01-01
    相关资源
    最近更新 更多