2017-04-15 3 views
1

ほとんどのコンテンツがページの下部に貼り付けられるようにするにはどうすればよいですか?どのように私のフッタを底にくっつけることができますか?

CSSで
<footer> 
<hr> 
<p> &copy; 2017 Sindre Berge <p> 
</footer> 
+0

http://stackoverflow.com/questions/42294/how-do-you-get-the-footer-to-stay-at-the-bottom-of-a-web -page –

+0

https://getbootstrap.com/examples/sticky-footer/およびhttp://getbootstrap.com/examples/sticky-footer-navbar/ –

答えて

0

<style> 
footer { 
    width:100%; 
    position: fixed; 
    bottom: 0px; 
    text-align: center; /* This line is not needed but centers your text */ 
    } 
</style> 

<footer> 
    <hr> 
    <p> &copy; 2017 Sindre Berge <p> 
</footer> 

はアクションでそれを参照して、ここでそれで遊ぶ:https://www.w3schools.com/code/tryit.asp?filename=FEO78PICTTQP

それともSamによって提案されたフレックス解決策を試してみてください。これにより、フッターがブラウザービューの下部に常に表示されるのではなく、ページの下部に表示されます。

フレックス溶液:

.flex-container { 
 
    display: -webkit-box; 
 
    display: -moz-box; 
 
    display: -ms-flexbox; 
 
    display: -webkit-flex; 
 
    display: flex; 
 
    -webkit-box-direction: normal; 
 
    -moz-box-direction: normal; 
 
    -webkit-box-orient: horizontal; 
 
    -moz-box-orient: horizontal; 
 
    -webkit-flex-direction: row; 
 
    -ms-flex-direction: row; 
 
    flex-direction: row; 
 
    -webkit-flex-wrap: wrap; 
 
    -ms-flex-wrap: wrap; 
 
    flex-wrap: wrap; 
 
    -webkit-box-pack: start; 
 
    -moz-box-pack: start; 
 
    -webkit-justify-content: flex-start; 
 
    -ms-flex-pack: start; 
 
    justify-content: flex-start; 
 
    -webkit-align-content: stretch; 
 
    -ms-flex-line-pack: stretch; 
 
    align-content: stretch; 
 
    -webkit-box-align: start; 
 
    -moz-box-align: start; 
 
    -webkit-align-items: flex-start; 
 
    -ms-flex-align: start; 
 
    align-items: flex-start; 
 
    /*I give height 700px but can be adapted to a body being 100%*/ 
 
    height:700px; 
 
    background:#cccccc; 
 
    } 
 

 
.flex-content { 
 
     -webkit-box-ordinal-group: 3; 
 
    -moz-box-ordinal-group: 3; 
 
    -webkit-order: 2; 
 
    -ms-flex-order: 2; 
 
    order: 2; 
 
    -webkit-box-flex: 0; 
 
    -moz-box-flex: 0; 
 
    -webkit-flex: 0 1 100%; 
 
    -ms-flex: 0 1 100%; 
 
    flex: 0 1 100%; 
 
    -webkit-align-self: flex-end; 
 
    -ms-flex-item-align: end; 
 
    align-self: flex-end; 
 
    background:#ca33aa; 
 
    height:100px; 
 
    }
<div class="flex-container"> 
 
    <div class="flex-content"> 
 
This is my footer 
 
    </div> 
 
    </div>

+0

Z-インデックスを999に設定しないでください。https://philipwalton.com/articles/what-no-one-told-you-about-z-index/ –

+0

こんにちは、フレックスソリューションを追加するように編集してください私の答えを取り除く。私はメリットはありませんが、私はそれが後に来るユーザーのための情報を完成させると思います。乾杯。 – Sam

1

footer{ 
    position:fixed; 
    bottom:0; 
    text-align: center; 
    width: 100%; 
} 

またはあなたはそれをインライン化できます。

<footer style="position:fixed; bottom:0; text-align: center; width: 100%;"> 
<hr> 
<p> &copy; 2017 Sindre Berge <p> 
</footer> 
+0

のオフィシャルの例を参照してください私はフッタp {text-align:center; } –

+0

以前のようにテキストのセンタリングを含めるように答えを更新しました。 –

0

私は個人的に、私はその時々見つけたよう

footer{ 
    position:absolute; 
    bottom:0; 
    width: 99%; 
} 

を使用したいですサイトは雑踏に行きます - 特にまでは、画面上にすべてがうまくフィットしているにもかかわらず、ときどき底の厄介な水平スクロールバーで挨拶されることがあります。 CSS使用

+1

幅を任意に変更するのではなく、ページがスクロールバーを追加している理由を調べたい場合があります。 –

+0

単なるスクリプトではなく、純粋なHTMLとCSSです。 –

+0

それは私を驚かせることはないでしょう。おそらく、余白、パディング、または幅が100%またはそれ以上の要素上にある境界線を既に持っています。 –

0

ブロック溶液:

footer { 
display:block; 
position:fixed; 
bottom:0; 
} 

フレックス溶液:

.flex-container { 
 
    display: -webkit-box; 
 
    display: -moz-box; 
 
    display: -ms-flexbox; 
 
    display: -webkit-flex; 
 
    display: flex; 
 
    -webkit-box-direction: normal; 
 
    -moz-box-direction: normal; 
 
    -webkit-box-orient: horizontal; 
 
    -moz-box-orient: horizontal; 
 
    -webkit-flex-direction: row; 
 
    -ms-flex-direction: row; 
 
    flex-direction: row; 
 
    -webkit-flex-wrap: wrap; 
 
    -ms-flex-wrap: wrap; 
 
    flex-wrap: wrap; 
 
    -webkit-box-pack: start; 
 
    -moz-box-pack: start; 
 
    -webkit-justify-content: flex-start; 
 
    -ms-flex-pack: start; 
 
    justify-content: flex-start; 
 
    -webkit-align-content: stretch; 
 
    -ms-flex-line-pack: stretch; 
 
    align-content: stretch; 
 
    -webkit-box-align: start; 
 
    -moz-box-align: start; 
 
    -webkit-align-items: flex-start; 
 
    -ms-flex-align: start; 
 
    align-items: flex-start; 
 
    /*I give height 700px but can be adapted to a body being 100%*/ 
 
    height:700px; 
 
    background:#cccccc; 
 
    } 
 

 
.flex-content { 
 
     -webkit-box-ordinal-group: 3; 
 
    -moz-box-ordinal-group: 3; 
 
    -webkit-order: 2; 
 
    -ms-flex-order: 2; 
 
    order: 2; 
 
    -webkit-box-flex: 0; 
 
    -moz-box-flex: 0; 
 
    -webkit-flex: 0 1 100%; 
 
    -ms-flex: 0 1 100%; 
 
    flex: 0 1 100%; 
 
    -webkit-align-self: flex-end; 
 
    -ms-flex-item-align: end; 
 
    align-self: flex-end; 
 
    background:#ca33aa; 
 
    height:100px; 
 
    }
<div class="flex-container"> 
 
    <div class="flex-content"> 
 
This is my footer 
 
    </div> 
 
    </div>

関連する問題