关于 IE 中 body 的 overflow: hidden 的 fix
今天工作中实际碰到的问题。我写在这里了:
http://www.cnblogs.com/rchen/archive/2005/02/22/107426.html
最终的文档是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="Roger Chen">
<meta name="keywords" content="">
<meta name="description" content="">
<style type="text/css">
html {/*Browser Hack proposed by Tantek Celik to correct IE5 box model misinterpretation*/
overflow: hidden; height: 100%; margin: 0; padding: 0;}
body {height: 99%; margin: 0; border: 0; padding: .5%; overflow: hidden;}
#test {overflow: hidden;}
#test {width: 300px; height: 100px; margin: auto; border: 1px solid green;}
</style>
</head>
<body>
a<br/>a<br/>
<div id="test">this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/>this is a test.<br/></div>
a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>
</body>
</html>
从这个可以看到在兼容标准的模式下,IE 中仅仅是 body 元素有 bug. 归根到底是 IE 对盒模型解释错误的表现之一.