2012-11-07 68 views
0

我想在水平居中的div中有一個iframe。它在Firefox中正常工作,但不在IE8中。這裏是我的完整代碼:iframe的高度和寬度居中

<!-- <!DOCTYPE HTML> --> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html><head></head> 
<STYLE type="text/css"> 
body { 
background-color: silver; } 

#container { 
align: right; 
margin: 0; 
width: 600px;height: 100%; 
margin: 10px auto; 
background-color: white; 
} 

#top { 
height: 300px; 
background-color: yellow; } 

#midpart { 
width:100%; 
height:100%; 
background-image:none; 
background-color: blue; } 

</style> 
<body> 
<div id="container"> 
<div id="top"> 
<iframe src="aa.htm" id="midpart" scrolling="yes" frameborder="1"></iframe> 
</div> 

</div> 
</body></html> 

在IE8上面的代碼產生一個不是水平居中的div。否則,它是確定的。 iFrame div佔據了屏幕的大約100%。請注意,我使用的是長文檔類型版本

如果我使用第一個doctype行(簡短的一行),IE8居中分隔,但div/iframe高度不正確。

任何其他解決方法?

回答

0

以下樣式添加到您的身體......

text-align:center; 
+0

謝謝! 「文本對齊:中心;」做到了。 – user1231247

+0

如果它幫助你,請隨時接受答案 – George

0

您的意思是有「保證金:10px的汽車」和「對齊:右」在#container的?

0
position:relative; 
margin:0 auto; 

應產生一個水平居中的頂部ID的div。您可以使用width和height屬性直接在iframe上設置寬度和高度。