0

高さを 100% 以上にしたい Web サイトを構築しているので、ページのコンテンツが多すぎない場合、フッターはページの下部に表示されます。より多くのコンテンツがある場合は、単純に拡張されます。

これを例としてWebサイトを使用し、必要に応じて変更しました。
最初はうまく機能しているように見えましたが、今では 2 つの問題が発生
しています。小さな部分が画面からはみ出しています。
- 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;
}   

コードを Fiddle に入れました: http://jsfiddle.net/7uuD6/1
(残念ながら、JSFiddle が処理できない ASP.NET コードが含まれています)

私は何を間違っていますか?乾杯、CJ

4

3 に答える 3

3

固定フッターを維持するために使用できる方法は 2 つありますが、ブラウザーのサポートによって異なります。

17 より前の IE7 または Firefox バージョンを気にしない場合は、box-model border-box プロパティを使用するこのアプローチを使用できます。

ボーダーボックス版

このために必要な要素は 2 つだけです。

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;
}
于 2013-05-14T09:56:11.023 に答える
0

そのために私はこれをお勧めします: 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 に適用して調整すると、問題なく動作します。

//注// 絶対フッターを使用するのは危険です!

于 2013-05-14T09:31:56.233 に答える
-1

このjqueryを試してください

スティッキーフッターjquery

于 2013-05-14T09:41:48.807 に答える