Voglio condividere con voi la mia soluzione per un footer fisso, senza bisogno di JavaScript (un’alternativa a questa richiesta), assumendo che conosciate l’altezza del vostro footer. Ho aggiunto 100px in più al mio per avere uno spazio tra il contenuto e il footer.
Nel caso abbiate un footer più grande con più colonne, dovreste impostare un’altezza fissa diversa nella scheda mobile.
Passo 1: Incolla questo nella scheda CSS comune
body {
position: relative;
}
#main {
margin-bottom: 350px; /* corrisponde all'altezza del footer: modificalo secondo le tue esigenze, sia nella scheda comune che in quella mobile */
}
#sticky-footer {
padding: 50px 0;
background: var(--header_background); /* opzionale */
color: var(--primary-medium); /* opzionale */
text-align: center; /* opzionale */
position: absolute;
bottom: 0;
width: 100%;
left: 0;
}
Passo 2: Vai alla scheda </body> e incolla il tuo HTML del footer all’interno
Esempio:
<div id="sticky-footer">
<div class="wrap">
<!-- il contenuto del tuo footer qui -->
</div>
</div>
È tutto . Ora il tuo footer rimarrà fissato in fondo alla pagina, anche su pagine con contenuto breve.
Ecco come appare il nostro footer su una pagina con contenuto breve:
You tell me Jeff …do we need to install components for every extra HTML and CSS code?
This is not a “how to create a footer” tutorial but more like a quick alternative solution to make a footer stick to the bottom of the page for those who may want to create their own footer.
Hmm, my thinking is we want people to use the theme components whenever possible as they are “official” from us and thus get full support, get auto updated, etc. What do @awesomerobot@Johani and @jordan.vidrine think?
Yeah if the official footer component fits your needs then it’s nice because we keep it up-to-date for you, but some people will want a different layout.
I’ve done something like this in the past… it’s a similar process to OP. You set the #main-outlet height to be 100% of the viewport height (100vh) minus the height of the footer and header. So on short pages your footer will now sit right at the bottom.
#main-outlet {
box-sizing: border-box; // includes padding in height calculation
}
It comes up often enough that it’s probably worth doing something like this in core automatically if there’s content in footer.html or either of the two footer plugin outlets.