2017-04-18 2 views
0

Mit HTML/CSS, ich brauche die footer zu bekommen auf den bottom der Seite platziert wird, auch wenn es no enough content.CSS - Legen Sie die Fußzeile auf der Unterseite der Seite, auch wenn kein genügend Inhalt

Wenn viel Inhalt einen Bildlauf verursacht, ist dies sehr einfach zu erreichen. Das Problem trat auf, wenn nicht genug Inhalt vorhanden war, da in diesem Fall die Fußzeile nach oben ging.

Hier haben Sie ein Bild, das dies verdeutlichen könnte:

enter image description here

Ich habe folgenden Startcode:

CSS

body { 
    margin: 0; 
} 
#header, #content, #footer { 
    padding: 10px; 
} 
#header { 
    height: 100px; 
    background-color: #abcdef; 
} 
#content { 
    bottom: 100px; 
    left: 0; 
    right: 0; 
    background-color: #F63; 
    overflow: auto; 
} 
#footer { 
    position: fixed; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    height: 100px; 
    background-color: #abcdef; 
} 

HTML

<div id="header"> 
There is the Header 
</div> 
<div id="content"> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
    hello world<br/> 
</div> 
<div id="footer"> 
There is the Footer 
</div> 

Jsfiddle Vorschau: https://jsfiddle.net/bk5ow9us/ (versuchen, die Höhe des Fensters Ändern der Größe)

Jede Idee, wie dies zu erreichen?

WICHTIG

Ich brauche eine funktionierende Lösung auch für IE (Version> = 11), nicht nur FF und Chrome.

+1

so? https://jsfiddle.net/bk5ow9us/1/ –

+0

FYI gibt es etwa 3.000 Fragen (wörtlich), die bereits auf der Website fragen. Ich wette, Sie könnten die Antwort mit ein wenig Suchen finden. – TylerH

+0

Ofc es ist ein Duplikat, diese Frage wird fast jeden Tag gestellt. Wir sollten sie auf die SO-Dokumente verweisen, die der ganze Sinn von ihnen ist – StefanBob

Antwort

1

Sie können ein Flexbox Sticky Footer Layout verwenden, wenn Sie möchten.

würde ich min-height: 100vh; statt height: 100%; verwenden obwohl

html, body { 
 
    min-height: 100vh; 
 
} 
 

 
body { 
 
    display: flex; 
 
    flex-direction: column; 
 
    margin: 0; 
 
} 
 

 
.content { 
 
    /* Include `0 auto` for best browser compatibility. */ 
 
    flex: 1 0 auto; 
 
} 
 

 
.header, .footer { 
 
    background-color: grey; 
 
    color: white; 
 
}
<div class="header"> 
 
    <h2>Header</h2> 
 
</div> 
 

 
<div class="content"> 
 
    <h1>Content</h1> 
 
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p> 
 
</div> 
 

 
<div class="footer"> 
 
    <h4>Footer</h4> 
 
</div>

+0

Haben Sie ein Beispiel-Beispiel? – Angel

+0

aktualisierte Antwort, auch wenn Sie einfach kopieren + einfügen, wie ich tat – StefanBob

+0

Es funktioniert nicht auf IE, überprüfen Sie dieses Bild: http://image.ibb.co/m1UAvk/image.png, muss ich etwas hinzufügen an das CSS, damit es dort funktioniert? – Angel

-1

ich hatte das gleiche Problem. Das hat es gelöst.

#footer { 
    position: absolute; 
    right: 0; 
    bottom: 0; 
    left: 0; 
} 
0

Sie können dies auf zwei Arten tun. Einer nutzt flexbox und setzt den Inhaltsbereich auf flex-grow, so dass er standardmäßig den verfügbaren Speicherplatz ausfüllt.

body { 
 
    margin: 0; 
 
    display: flex; 
 
    flex-direction: column; 
 
    min-height: 100vh; 
 
} 
 
#header, #content, #footer { 
 
\t padding: 10px; 
 
} 
 
#header { 
 
    height: 100px; 
 
    background-color: #abcdef; 
 
} 
 
#content { 
 
    flex: 1 0 0; 
 
    background-color: #F63; 
 
} 
 
#footer { 
 
    height: 100px; 
 
    background-color: #abcdef; 
 
}
<div id="header"> 
 
There is the Header 
 
</div> 
 
<div id="content"> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
</div> 
 
<div id="footer"> 
 
There is the Footer 
 
</div>

Oder Sie können absolut die Fußzeile positionieren, und verwenden Sie padding auf body den Raum zu reservieren, in dem die Fußzeile sein wird.

* {box-sizing:border-box;} 
 
body { 
 
    margin: 0; 
 
    padding-bottom: 100px; 
 
    position: relative; 
 
} 
 
#header, #content, #footer { 
 
\t padding: 10px; 
 
} 
 
#header { 
 
    height: 100px; 
 
    background-color: #abcdef; 
 
} 
 
#content { 
 
    left: 0; 
 
    right: 0; 
 
    background-color: #F63; 
 
} 
 
#footer { 
 
    position: absolute; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    height: 100px; 
 
    background-color: #abcdef; 
 
}
<div id="header"> 
 
There is the Header 
 
</div> 
 
<div id="content"> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/>hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
\t hello world<br/> 
 
</div> 
 
<div id="footer"> 
 
There is the Footer 
 
</div>

Verwandte Themen