5546 sujets

Sémantique web et HTML

Bonjour,

Je n'arrive pas à me décider pour créer un footer collé en bas de page, entre deux méthodes : 1ère et 2ème.

- La première, qui fonctionne sans restrictions, génère une div vide qui pousse le footer
* {
	margin: 0;
}
html, body {
	height: 100%;
}
.wrapper {
	min-height: 100%;
	height: auto !important;
	height: 100%;
	margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
	height: 142px; /* .push must be the same height as .footer */
}

/*

Sticky Footer by Ryan Fait
 http://ryanfait.com/
 

*/

   <div class="wrapper"> </div>
<div class="push"> </div>
</div>
<div class="footer"> </div>

- La deuxième (plutôt plébiscitée) implique des commentaires conditionnelles pour Ie, voir même du code supplémentaire pour un bug d'Opéra.
/*  
Sticky Footer Solution
by Steve Hatcher 
*/

* {margin:0;padding:0;} 

/* must declare 0 margins on everything, also for main layout components use padding, not 
vertical margins (top and bottom) to add spacing, else those margins get added to total height 
and your footer gets pushed down a bit more, creating vertical scroll bars in the browser */

html, body {height: 100%;}

#wrap {min-height: 100%;}

#main {overflow:auto;
	padding-bottom: 180px;}  /* must be same height as the footer */

#footer {position: relative;
	margin-top: -180px; /* negative value of footer height */
	height: 180px;
	clear:both;} 

/*Opera Fix*/
body:before {/* thanks to Maleika (Kohoutec)*/
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;/* thank you Erik J - negate effect of float*/
}



/* IMPORTANT

You also need to include this conditional style in the <head> of your HTML file to feed this style to IE 6 and lower and 8 and higher.

<!--[if !IE 7]>
	<style type="text/css">
		#wrap {display:table;height:100%}
	</style>
<![endif]-->

*/


<div id="wrap">
	<div id="main">
	</div>
</div>
<div id="footer">
</div>
			

Merci pour vos réponses.
Modifié par rodolpheb (08 Feb 2013 - 11:49)
Bonjour,

Je suis également intéressée par un retour spécialiste.

Les div vident, ce n'est pas très propre... mais est-ce déconseillés ?
Merci,

KaySix
Les div vident se remplacent par un padding-bottom de même hauteur que le footer sur le dernier élément dans le flux.

Pour ie8 et plus on peut partir sur du display:table
ex http://result.dabblet.com/gist/4340095

et pour les autres passer en CC par du position:relative/absolute + padding sur section.

++