当前位置: 代码迷 >> HTML/CSS >> 很诡异的overflow:hidden 与fixed有关问题
  详细解决方案

很诡异的overflow:hidden 与fixed有关问题

热度:679   发布时间:2013-01-04 10:04:14.0
很诡异的overflow:hidden 与fixed问题
<!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=gb2312" /> 
<title>test</title> 
<script type="text/javascript" src="http://img.jb51.net/jslib/jquery/jquery.js"></script> 
<style type="text/css"> 
body{padding:10px;margin:0;} 
#box{width:200px; height:200px; float:left; overflow:hidden;margin:0 auto; background:#9C0;} 
.box2{ width:200px; height:300px; overflow:hidden; background:#CCC; position:fixed;}
</style> 
</head> 
<body> 
<div id="box"> 
<div class="box2"></div>
</div> 
</body> 
</html> 


#box高为200px,加上overflow:hidden理论上能对.box2超出部份隐藏,但实际上不尽人意,去掉.box2的position:fixed后就能隐藏超出部份了,在.box2的position:fixed不去掉的情况下求解决办法。
------解决方案--------------------
这个好像实现不了。
因为fixed 生成绝对定位的元素,相对于浏览器窗口进行定位,元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。
除非你将position类型换成static、relative或inherit。 
------解决方案--------------------
position:fixed;
将跳出标准文件流,也就是说fixed 是针对窗口本身的,因此设置 id="box" 的属性是无法生效的。你的用意是什么呢
------解决方案--------------------
W3C的官网明确规定了, position:fixed表示,这个div是相对于浏览器窗口来定位,

而不是受其他div影响,这个一点也不诡异,是你理解不到位吧。

最后给你引用下官网的参考:
 http://www.w3school.com.cn/css/pr_class_position.asp
  相关解决方案