2016-04-12 6 views
0

これはよくある問題ですが、私はこれを解決できません。どのように多くの設定を組み合わせても、ページの下部にはフッターが残りません。それはそれ以外のものの下に座るだけです。ページの下部にフッターを置いておきますか?

body { 
    margin: 0; 
    background-color: #ACFAB7; 
} 

# container { 
    margin: 0 auto; 
    padding: 40px; 
} 

#header { 
    z-index: 0; 
    height: 78px; 
    background-color: #2ecc71; 
} 

#footer { 
    z-index: 2; 
    height: 40px; 
    width: 100%; 
    padding: 0px; 
    position: relative; 
    background-color: #2ecc71; 
    /*display required to center text*/ 
    display: table; 
    text-align: center; 
    margin-left: auto; 
    margin-right: auto; 
} 

#image { 
    z-index: 1; 
    margin: 20px auto; 
    padding: 50px; 
} 

/*Centers text within the header*/ 
span { 
    display: table-cell; 
    vertical-align: middle; 
} 
+0

メーク#footer位置:絶対と下を追加します。0PXをそれに。 –

+0

さらに@sagarkodteのコメントでは、大きなページには 'position'を取り消す必要があることに注意してください。あなたのウェブサイトが公開されている場合は、私たちの自己をチェックするためのeaiserになります。 –

+0

フレックスボックスを絶対位置決めに使用することを検討してください。 – alesc

答えて

1

あなたは多くの問題があります。このソリューションは、

  • ページの末尾にフッターを固定します。
  • 内容を(縦と横の両方に)センタリングする。

修正

  • display: tableを取り除きます。
  • width: 100%を取り除く。
  • relativeからfixedに変更してください。

#footer { 
 
    z-index: 2; 
 
    line-height: 40px; 
 
    padding: 0px; 
 
    position: fixed; 
 
    background-color: #2ecc71; 
 
    text-align: center; 
 
    left: 0; right: 0; 
 
    bottom: 0; 
 
}
<div id="footer">Copyrights.</div>

+1

私たちは大きな高さを持っている場合、これは良い解決策ではありません –

+1

@AdnanAkramああ?どうして?面白い。私はこの方法を何度も使いました。このソリューションの問題点は何ですか?熱望して理解する。ありがとう。 –

+0

高さが200pxのフッターがある場合はposition:fixedを使用します。それは多くのスペースを取ると、常にブラウザの下部にスティックするので、表示:テーブル。完璧です –

0

あなたはposition: fixed; bottom: 0を使用することができます。

#footer { 
 
    z-index: 2; 
 
    height: 40px; 
 
    width: 100%; 
 
    padding: 0px; 
 
    background-color: #2ecc71; 
 
    text-align: center; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    position:fixed; 
 
    bottom:0; 
 
    left: 0; 
 
}
<div> 
 
    <footer id="footer">Footer</footer> 
 
</div>

+0

なぜ 'display:table'と他のもの? –

+0

右、他に何もする必要はありません:) – pradeep1991singh

0

position: fixed;bottom: 0;はトリックを行う必要があります。幅と高さを必要に応じて追加します。

.footer { 
 
    position: fixed; 
 
    bottom: 0; 
 
    width: 100%; 
 
    height: 30px; 
 
    background-color: aquamarine; 
 
}
<div style="background-color: lightgrey;height: 800px"> 
 
    Page content 
 
</div> 
 
<div class="footer"> 
 
    this is the footer 
 
</div>

+0

コンテンツの「高さ」がウィンドウよりも大きい場合は、中央に表示されます。あなたはこれを試しましたか? –

+1

@PraveenKumar:それを指摘してくれてありがとう。私は 'position:fixed'を使ってコードを更新しました。 – Pugazh

関連する問題