2010-04-02 83 views
1

无论何时向下滚动页面,我都希望在我的网页上显示标题DIV和页脚DIV 总是CSS/HTML:如何用CSS模拟IFRAME?

如何做到这一点只用CSS(不含iframe)

例如:

<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> 

回答

1

如果你能避免IE 6,那么你可以使用position: fixed

喜欢的东西

<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> 

A Better Fixed Positioning for Internet Explorer 6

+0

连同'top:0;'表示页眉,'bottom:0;'表示页脚。 – 2010-04-02 04:07:46

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

但请不要用这个。你的用户会恨你并离开该网站。

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; 
}