以下行爲與我在Firefox和Safari中預期的完全相同,但Internet Explorer的解決方案無法實現。通過絕對定位將100%高度容器推出IE瀏覽端口
問題:非IE瀏覽器顯示容器被正確推離視口的兩側。但是,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>
絕對定位的容器可容納兩個50%的高度元素。
要求如下:
- 容器的定位是任意的,但必須將其推離視區的側面遠離而無需依賴於填充的視口。
- 當調整視口大小時,容器中兩個元素的高度必須根據百分比值(當前各爲50%)調整大小。
- 這必須至少在IE 7+和Firefox 3+中運行。
- 如果這導致「OH DUH!」對我來說,你會盡力避免傷害。
我已經嘗試過HTML和BODY元素上的位置和高度屬性的許多組合,但顯然沒有在IE中找到正確的屬性。
您的代碼在IE 8,FF 3.6和Chrome v8中的工作原理完全相同。不過,我不能說早期版本。 – Patches 2011-01-07 21:35:36