本文主要包含IE6,position等相关知识,佚名 希望在学习及工作中可以帮助到您
然后,开始写代码,测试,最终,IE6下依然有问题。position:fixed;没有正常显示。

正确的代码:预览/Demo | ie6_position_fixed_bug.txt(源代码)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IE6 position:fixed bug</title> <style> * { padding:0; margin:0; } #rightform { text-align:center; padding:50px; font:14px/22px Georgia, "Times New Roman", Times, serif; height:1200px; background:#ffc; } #rightform h1 { font-family:arial; background:#e8edef; height:300px; line-height:300px; margin-bottom:200px; } #rightform p { line-height:1.5em; background:#ffdfff; padding:90px 0; } #rightform form { background-color:#ddd; padding:10px 20px; border:1px solid #aaa; position:fixed; right:30px; top:120px; } </style> <!--[if IE 6]> <style type="text/css"> html{overflow:hidden;} body{height:100%;overflow:auto;} #rightform form{position:absolute;} </style> <![endif]--> </head> <body> <div id="rightform"> <h1> <a href="" title="IE6 position:fixed bug" rel="bookmark">IE6 position:fixed bug</a> </h2> <p>position:fixed; vs position:absolute; support by <a href="http://www.jb51.net/" title="微课江湖">微课江湖</a> from jb51.net</p> <form id="g_search" method="get" action="#"> <input id="g_s" name="g_s" type="text" value="" /> <input id="g_submit" name="g_submit" type="button" value="search" /> </form> </div> </body> </html>
提示:您可以先修改部分代码再运行
在别的文章中看到,可以用position:absolute;来解决IE6的问题,不过,添加position:absolute;之后,依然没有成功。当然,最终,还是用position:absolute;来解决。只是,不一定能成功。因为,有一句非常重要的话需要理解。
我们需要做的是,让body保持其原有高度,让html只有一个窗口那么高。代码我们可以这样写:
完整代码请看上面链接提供的txt文件。问题的原理就是这么简单。不知道,你能理解不?

正确的代码:预览/Demo | ie6_position_fixed_bug.txt(源代码)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IE6 position:fixed bug</title> <style> * { padding:0; margin:0; } #rightform { text-align:center; padding:50px; font:14px/22px Georgia, "Times New Roman", Times, serif; height:1200px; background:#ffc; } #rightform h1 { font-family:arial; background:#e8edef; height:300px; line-height:300px; margin-bottom:200px; } #rightform p { line-height:1.5em; background:#ffdfff; padding:90px 0; } #rightform form { background-color:#ddd; padding:10px 20px; border:1px solid #aaa; position:fixed; right:30px; top:120px; } </style> <!--[if IE 6]> <style type="text/css"> html{overflow:hidden;} body{height:100%;overflow:auto;} #rightform form{position:absolute;} </style> <![endif]--> </head> <body> <div id="rightform"> <h1> <a href="" title="IE6 position:fixed bug" rel="bookmark">IE6 position:fixed bug</a> </h2> <p>position:fixed; vs position:absolute; support by <a href="http://www.jb51.net/" title="微课江湖">微课江湖</a> from jb51.net</p> <form id="g_search" method="get" action="#"> <input id="g_s" name="g_s" type="text" value="" /> <input id="g_submit" name="g_submit" type="button" value="search" /> </form> </div> </body> </html>
提示:您可以先修改部分代码再运行
在别的文章中看到,可以用position:absolute;来解决IE6的问题,不过,添加position:absolute;之后,依然没有成功。当然,最终,还是用position:absolute;来解决。只是,不一定能成功。因为,有一句非常重要的话需要理解。
fixed元素的绝对位置是相对于HTML元素来说,滚动条是body元素的。(via,刚才竟然没找到来源,囧。)
只有记住了这句话,才知为什么position:absolute;很多地方都给出了结果,但当时并未能解决。因为html被我设置position:relative。是上面这一句启发了我,最终才能够解决这个问题。我们拉动滚动条的时候,内容都会随着窗口滚动;这时滚动的是body。如果让绝对定位的父级元素定为body,刚我们需要固定的某个模块将会固定在网页的某个位置,而不是固定在窗口的某个位置(貌似在firefox中,html与body之间的介限并不明确?)。我们需要做的是,让body保持其原有高度,让html只有一个窗口那么高。代码我们可以这样写:
完整代码请看上面链接提供的txt文件。问题的原理就是这么简单。不知道,你能理解不?