我在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以及链接到的所有资源(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放在页面<style><head>标记中,但是通常最好将它放在单独的.css文件中,并链接到页面的<head>中,例如所以:

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


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

关于css - 如何使页脚贴在asp.net页面上?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29731213/

10-12 00:14
查看更多