一般要固定某个div,我们都会让该div{position:fixed},它的下一个div{position:absolute}看了几个国外的关于CSS的固定定位跨浏览解决方案.他们却反其道而为之:看示例吧:
- <style type="text/css">
- body{
- margin:0;
- padding:30px 0 0 0;
- }
- div#menu{
- position:absolute; top:0;
- left:0;
- width:100%;
- height:30px;
- background-color:#ddd;
- }
- @media screen{
- body>div#menu{
- position:fixed;
- }
- }
- * html body{
- overflow:hidden;
- }
- * html div#content{
- height:100%;
- overflow:auto;
- }
- </style>
HTML示例:
- <!-- quirksmode -->
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <title>Demo</title>
- <link href="fixed.css" rel="stylesheet" type="text/css">
- </head>
- <body>
- <div id="menu">
- Mozilla
- Opera
- Netscape
- Firefox
- IE6
- Windows
- Style
- CSS
- </div>
- <div id="content">
- 只要内容大于一屏的高度就行
- </div>
- </body></html>
你删除第一行注释看看效果如何?