繁体   English   中英

现场最小高度100%

[英]Site min-height 100%

我正在构建一个我希望最小高度为100%的网站,所以如果页面上没有太多内容,则页脚将位于页面底部。 如果有更多内容,它只会扩展。

我使用了一个以此为例的网站,并将其改为我的需求。
起初它似乎工作得很好,但现在它显示出两个问题:
- 该网站的高度似乎总是超过100%; 一小部分延伸到屏幕之外。
- 虽然设置了Bottom属性,但页脚不会显示在底部,而是显示在中间的某个位置。

这是标记:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Master Language="VB" CodeFile="Site.Master.vb" Inherits="Site" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head id="Head" runat="server">
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Site (b&egrave;ta)</title>
    </head>
    <body>
        <form id="form1" runat="server" autocomplete="off" class="formCss">
            <ajax:ToolkitScriptManager ID="Toolscriptmanager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true">
                <Scripts>
                    <asp:ScriptReference Path="~/js/jquery-1.8.2.min.js" />
                    <asp:ScriptReference Path="~/js/jquery.curvycorners.packed.js" />
                    <asp:ScriptReference Path="~/js/Site.jquery.js" />
                    <asp:ScriptReference Path="~/js/jquery.colorize-1.3.1.js" />
                </Scripts>
            </ajax:ToolkitScriptManager>
            <asp:Label ID="ContentTitle" runat="server" CssClass="content_title"></asp:Label>
            <div id="container">
                <div id="headerContainer">
                    <div id="header">
                        <telerik:RadMenu ID="HoofdMenu" EnableEmbeddedSkins="false" Height="20px" EnableImageSprites="false" Font-Size="11px" runat="server" CollapseDelay="0" ExpandDelay="0" ClickToOpen="true" ExpandAnimation-Type="None" CollapseAnimation-Type="None" CausesValidation="false"></telerik:RadMenu>
                    </div>
                </div>

                <div id="content">
                    <asp:ContentPlaceHolder ID="Content" runat="server"></asp:ContentPlaceHolder>
                </div>
                <div id="footer">
                    This is the footer
                </div>
            </div>
       </form>
    </body>
</html>

这是CSS:

html,body 
{
    margin:5px;
    padding:0;
    height:100%; /* needed for container min-height */  
    font-family:tahoma;
    font-size:11px;
    color:#000000;
    background-color: #8FB1B1;  
    /*background-image: url(../../Images/Afbeelding1.jpg);*/
}

.formCss
{
    height:100%;
    min-height: 100%;
}

div#container 
{
    position:relative; /* needed for footer positioning*/
    margin:0 auto; /* center, not in IE5 */
    width:100%;     
    height:auto !important; /* real browsers */
    height:100%; /* IE6: treaded as min-height*/
    min-height:100%; /* real browsers */

    background-color: #FFFFFF;  
}

div#headerContainer
{
    background-color: #8FB1B1;
}
div#header 
{
    padding-left:5px;
    padding-top: 12px;  
    height: 30px;   
    background-color: #1C2948;  /*#833D62;*/
    z-index: 100;
}


div#content 
{
    padding-left: 10px;
    padding-right: 10px;
    padding-top:10px;   
    background-color: #FFFFFF; /* #E0E5D7; #FFFFFF;*/
    padding-bottom:25px;  /* bottom padding for footer */

    /*filter:alpha(opacity=80); 
    -moz-opacity:0.80; 
    opacity:0.80;   */

}   

div#footer 
{
    position:absolute;
    height: 25px;   
    bottom:0; /* stick to bottom */
    background:#FFFFFF;     
    padding-left: 10px;
}   

我把代码放在一个小提琴: http//jsfiddle.net/7uuD6/1
(它包含JSFiddle无法处理的ASP.NET代码,不幸的是)

我究竟做错了什么? 干杯,CJ

您可以使用两种方法来维护粘性页脚,但它们取决于您的浏览器支持。

如果您不关心早于17的IE7或Firefox版本,则可以使用此方法使用box-model border-box属性。

边框版本

为此,您只需要两个元素。

HTML

<div class="page">    
</div> 
<div class="page-footer">
</div>

CSS

*, *:before, *:after {
    /* Fix the box model to include padding */
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    position: relative;
}

.page {
    min-height: 100%;
    position: relative;
    margin-bottom: -150px;
    padding-bottom: 150px;
}

.page-footer {
    height: 150px;
    position: relative;
    z-index: 1;
}

如果您需要支持旧浏览器,那么您将需要使用额外的div来推送页脚。

遗产版本

此版本所需的代码如下。

HTML

<div class="page">
    <div class="page-push">
        <!--
            This div just pushes the footer down so content does not overflow it
        -->
    </div>
</div> 
<div class="page-footer">
</div>

CSS

html, body {
    height: 100%;
    margin: 0;
    position: relative;
}

.page {
    min-height: 100%;
    position: relative;
    margin-bottom: -150px;
}

.page-push,
.page-footer{
    height:150px;
}

.page-footer {
    position: relative;
    z-index: 1;
}

为此我建议: http//matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page

div#container {
   min-height:100%;
   position:relative;
}
div#header {
   background:#ff0;
   padding:10px;
}
div#content {

   padding-bottom:___px;   /* Height of the footer */
}
div#footer {
   position:absolute;
   bottom:0;
   width:100%;
   height:___px;   /* Height of the footer */
   background:#6cf;
}

如果你申请并调整你的html / css它会很好。

//注意//使用绝对页脚是一种风险!

试试这个jquery

粘性页脚jquery

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM