我在想,如果有有一個想法如何與IE7以下問題,以解決人:IE7相對/絕對定位的臭蟲以動態修改頁面內容
<!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>
<title>IE7 absolute positioning bug</title>
<style type="text/css">
#panel { position: relative; border: solid 1px black; }
#spacer { height: 100px; }
#footer { position: absolute; bottom: 0px; }
</style>
<script type="text/javascript">
function toggle() {
var spacer = document.getElementById("spacer");
var style = "block";
if (spacer.style.display == "block" || spacer.style.display == "") {
style = "none";
}
spacer.style.display = style;
}
</script>
</head>
<body>
<div id="panel">
<button onclick="toggle();">Click me</button>
<br /><br /><br />
<div id="spacer"></div>
<div id="footer">This is some footer</div>
</div>
</body>
</html>
當您在IE7運行這個你會看到在修改「面板」的CSS後,「頁腳」元素保持不變。在IE8,FF和Chrome中測試的相同示例的行爲完全如預期。
我已經嘗試過更新元素的類,但是如果瀏覽器的窗口已經最大化打開並且沒有對窗口做進一步的大小修改(這大約有90%的用例是我們的產品.... :() 我堅持使用基於CSS的解決方案,但是我認爲如果可以很容易地製作IE7特定的(這意味着其他瀏覽器將在這個標準的方式)。
請幫幫忙!
您是否嘗試過交換的文檔類型爲html嚴格或XHTML嚴格?然後會發生什麼? – NotMe 2010-03-18 20:43:01
的確我沒有。問題是我無法控制doctype發送給客戶端的原因(因爲我無法在這裏討論),所以即使它已經工作也不會是解決方案... – 2010-04-28 08:32:02
2年後,問題(和答案)仍然非常有用!一段時間以來,我一直在嘲笑我的頭。甚至無法弄清楚如何正確地說出問題......謝謝! – 2012-04-03 13:32:24