2010-04-02 6 views
1

Je souhaite avoir un en-tête DIV et un pied de page DIV toujours affiché sur ma page Web, quel que soit le moment où vous faites défiler la page.CSS/HTML: Comment simuler IFRAME avec CSS?

Comment puis-je y parvenir en utilisant uniquement CSS (sans IFRAMES)

Par exemple:

<div id=header>Always display on top, regardless if you have scrolled down the page</div> 
<div id=main_content>...</div> 
<div id=footer>Always display on the bottom</div> 

Répondre

1

Si vous pouvez éviter IE 6, vous pouvez utiliser position: fixed.

Quelque chose comme

<style type="text/css"> 
    #header { position: fixed; top: 0px; } 
    #main_content { height: 1200px; } 
    #footer { position: fixed; bottom: 0px; } 
</style> 
<div id=header> 
    Always display on top, regardless if you have scrolled down the page 
</div> 
<div id=main_content>...</div> 
<div id=footer> 
    Always display on the bottom 
</div> 

Voir A Better Fixed Positioning for Internet Explorer 6

+0

Avec 'top: 0;' pour l'en-tête et 'bottom: 0;' pour le pied de page. –

0
#header { position: fixed; } 
#footer { position: fixed; } 

Mais s'il vous plaît ne pas utiliser. Vos utilisateurs vous détesteront et quitteront le site.

0
#header{ 
left:0; 
top:0; 
height:100px; 
width:100%; 
position:fixed; 
z-index:2; 
background:grey; 
} 
#main_content{ 
margin-top:100px; 
margin-bottom:100px; 
height:1000px; 
} 
#footer{ 
bottom:0; 
left:0; 
height:100px; 
width:100%; 
position:fixed; 
z-index:2; 
background:grey; 
}