Heim  >  Artikel  >  Web-Frontend  >  IE6,IE7下设置body{overflow:hidden;}失效Bug (转)_html/css_WEB-ITnose

IE6,IE7下设置body{overflow:hidden;}失效Bug (转)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:35:001134Durchsuche

此项其实并不是Bug,只是各浏览器默认付值不同造成的,其他明智的浏览器还好,这个bug只出现在IE6 IE7下

 

问题重现:

<p>There are no scrollbars on this page in sane browsers</p>html, body, p {    margin: 0;    padding: 0;}body {    overflow: hidden;}p {    width: 5000px;    height: 5000px;}

 

IE6 IE7下不生效(IE6下横向纵向滚动条都在 IE7下纵向滚动条还在)

原因:

明智的浏览器(ex. chrome and firefox)会初始付值给html{overflow:visible;}

IE6 初始付值html{overflow-x:auto;overflow-y:scroll;}

IE7 初始付值html{overflow-x:visible;overflow-y:scroll;}

只有dom根结点(也就是html根节点)设置html{overflow:visible;}的时候,浏览器才会将body元素中的overflow值应用到视图区。

举个例子说:

设置了body{overflow:hidden},还会出现滚动条,不过这个滚动条不是body的,是html的
只有你设置html{overflow:visible;} body{overflow的值}才能传递到html{}中去
这样html的值就变成了{overflow:hidden},ok没有滚动条了

这样就很明了啦,并不是bug,而是浏览器初始值不同产生的问题。

 

解决办法:

html, body, p {    margin: 0;    padding: 0;}html {    overflow: visible;}body {    overflow: hidden;}p {    width: 5000px;    height: 5000px;}

 

此项可以整理到自己的reset文件中去

 

via 飞长'blog 原文地址

 

 

 

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn