>  기사  >  웹 프론트엔드  >  很诡异的overflow:hidden 与fixed问题_html/css_WEB-ITnose

很诡异的overflow:hidden 与fixed问题_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 12:16:271948검색

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.