2010-12-15 156 views
0

我想我的網頁看起來像這樣:IE問題:事業部定位

+------+------+ 
|first |third | 
|  |  | 
+------+------+ 
|second|  
|  |  
+------+ 

在FF和Chrome瀏覽器的最新版本剪斷下面的作品,因爲它應該。但在IE瀏覽器的輸出是這樣的:

+------+ 
|first | 
|  |  
+------+------+ 
|second| third|  
|  |  | 
+------+------+ 

我剪斷

<style> 
    #wrapper 
    { 
     width: 680px; 
    } 

    #first 
    { 
     background: Red; 
     float: left; 
     width: 500px; 
    } 

    #second 
    { 
     background: Green; 
     float: left; 
     width: 500px; 
    } 

    #third 
    { 
     background: Red; 
    } 
</style> 
<div id="wrapper"> 
    <!-- 1st two Divs--> 
    <div id="first">Div ONE</div> 
    <div id="second">Div TWO</div> 
    <!-- 3rd Div should be on the top right side next to div one --> 
    <div id="third">Div Three</div> 
</div> 

我真的很感激,如果你能給我一個解決方案不會改變HTML標記

謝謝你的時間!

瑞士安德魯

+0

你有沒有試過float:right for the third div? – Catalin 2010-12-15 12:58:05

+0

是的,但它不會產生正確的輸出。 – Andrew 2010-12-15 12:59:54

+0

您使用的是哪個版本的IE? – Lazarus 2010-12-15 13:00:16

回答

0

這裏,這應該工作:

#wrap { width:800px; position:relative; } 
#first, #second, #third { width:400px; height:400px; } 
#third { position:absolute; top:0; right:0; } 

工作演示:http://vidasp.net/tinydemos/layout.html

+0

這是一個相當不靈活的解決方案。如果第三個容器的內容需要1200px高度怎麼辦? – lnrbob 2010-12-15 13:33:21

+0

謝謝!這個解決方案適用於我,因爲第三個div永遠不會比其他的更高。 – Andrew 2010-12-16 13:42:24

1

試試這個:

<style> 
    #wrapper 
    { 
     width: 680px; 
    } 

    #first 
    { 
     background: Red; 
     float: left; 
     width: 500px; 
    } 

    #second 
    { 
     background: Green; 
     width: 500px; 

    } 

    #third 
    { 
     background: Red; 
     float: left; 

    } 
</style> 

你不得不浮在第三格左邊,並從第二個div去除浮動。

您將不必編輯HTML,但將不得不重新排序的div:

<div id="wrapper"> 
    <div id="first">Div ONE</div> 
    <div id="third">Div Three</div> 
    <div id="second">Div TWO</div> 
</div> 

這會給你顯示你正在尋找的順序。

+0

非常感謝您的答案,但正如我所說的,該HTML應該是未觸及的。 – Andrew 2010-12-15 13:09:06

+0

我有另一個解決方案,它將保持html不變,但它取決於框的尺寸 - 它們是否被修復? – SMSidat 2010-12-15 13:23:05

0

怎麼是這樣的:

<style> 
    #wrapper 
    { 
     width: 680px; 
    } 

    #first-second-wrapper { 
     float: left; 
     width: 500px; 
    } 

    #first 
    { 
     background: Red; 
    } 

    #second 
    { 
     background: Green; 
    } 

    #third 
    { 
     background: Red; 
     margin-left: 500px; 
    } 
</style> 
<div id="wrapper"> 
    <!-- 1st two Divs--> 
    <div id="first-second-wrapper"> 
     <div id="first">Div ONE</div> 
     <div id="second">Div TWO</div> 
    </div> 
    <!-- 3rd Div should be on the top right side next to div one --> 
    <div id="third">Div Three</div> 
</div> 
+0

非常感謝,但是沒有解決方案讓html保持原樣嗎? – Andrew 2010-12-15 13:10:40

+0

@Andrew是的,但它取決於盒子的尺寸... – 2010-12-15 13:12:46

0

我不知道哪個你的IE版本正在測試,但這在我的IE8中正確渲染。當我使用開發工具欄切換到IE7標準模式時,我遇到了問題。這可以用這個CSS來解決:

#second 
    { 
     background: Green; 
     float: left; 
     width: 500px; 
     clear:both; 
    } 

您可能需要爲我不確定其他瀏覽器上的效果,包括這一個條件註釋。這裏是an example這個。