[英]100% height container is pushed out of IE viewport by absolute positioning
The following behaves exactly as I expect it to in Firefox and Safari, but the solution for Internet Explorer eludes me. 以下行为完全符合我在Firefox和Safari中的预期,但是Internet Explorer的解决方案使我难以理解。
The Issue : Non-IE browsers show the container properly pushed away from the sides of the viewport. 问题 :非IE浏览器显示容器已正确地从视口的侧面推开。 IE however, maintains a strict 100% height on the container (presumably based on a parent of that container) and instead offsets the container, pushing it off the bottom of the viewport.
但是,IE在容器上保持严格的100%高度(大概基于该容器的父级),而是偏移容器,将其推离视口底部。
<!DOCTYPE html>
<html>
<title>The Splits</title>
<head>
<style>
html, body {margin:0;padding:0;height:100%;}
html {
height:auto;
min-height:100%;
overflow:hidden;
}
div#container {
position:absolute;
top:50px;
right:20px;
bottom:20px;
width:290px;
max-height:100%;
#height:100%;
}
div#one,
div#two {
position:relative;
height:50%;
overflow:auto;
}
div#one {background-color:lightgreen;}
div#two {background-color: lightblue;}
</style>
</head>
<body>
<div id="container">
<div id="one">top</div>
<div id="two">bottom</div>
</div>
</body>
</html>
An absolutely positioned container holds two 50% height elements. 绝对放置的容器可容纳两个高度为50%的元素。
Requirements are as follows: 要求如下:
I've tried many combinations of position and height attributes on the HTML and BODY elements, but apparently have not hit upon the right one for IE. 我已经尝试了HTML和BODY元素上的position和height属性的许多组合,但是显然没有针对IE找到合适的组合。
This uses a little IE specific (nonstandard) code to fix the behavior for IE7. 这使用一些特定于IE的(非标准)代码来修复IE7的行为。 Nothing gets changed for other browsers.
其他浏览器没有任何改变。
<!DOCTYPE html>
<html>
<title>The Splits</title>
<head>
<!-- saved from url=(0014)about:internet -->
<style>
html, body {margin:0;padding:0;height:100%;}
html {
height:auto;
min-height:100%;
overflow:hidden;
}
div#container {
position:absolute;
top:50px;
right:20px;
bottom:20px;
width:290px;
max-height:100%;
#height:100%;
}
div#one,
div#two {
position:relative;
height:50%;
overflow:auto;
}
div#one {background-color:lightgreen;}
div#two {background-color: lightblue;}
</style>
<!--[if IE 7]>
<style>
div#one,
div#two {
height:expression(((this.parentElement.offsetHeight-70)/2)+'px');
}
</style>
<![endif]-->
</head>
<body>
<div id="container">
<div id="one">top</div>
<div id="two">bottom</div>
</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.