簡體   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