2014-10-11 178 views
0

這讓我瘋狂。CSS自動寬度div

情況如下。
我有1個包裝div需要跨越屏幕的整個寬度/高度。
我需要1個位於屏幕右側並具有固定寬度(例如100px;)的div。
然後其他div需要跨越屏幕的剩餘左半部分(沒有更多!)。

注意:我不想浮動元素,我真的需要div跨越屏幕的整個高度,因爲Google Map會加載到div中。
我知道css中的calc函數,但我不想使用它,因爲IE8不支持它。

http://jsfiddle.net/gze4vcd2/

<div id="wrapper"> 
    <div id="left"></div> 
    <div id="right"></div> 
</div> 

#wrapper{ 
    position: relative; 
    width: 100%; 
    height: 100%; 
    background: greenyellow; 
} 

#left{ 
    position: absolute; 
    left: 0; 
    width: auto; 
    background: blue; 
} 

#right{ 
    position: absolute; 
    right: 0; 
    height: 100%; 
    width: 200px; 
    background: yellow; 
} 

這並不在所有的工作。
我已經嘗試了各種各樣的東西,但我無法讓它工作。

+0

作品更新的代碼看起來你想要的 「絕對定位」?餿主意。 – 2014-10-11 05:27:18

+0

這不像您有使用Google地圖的選擇。 – Trace 2014-10-11 05:29:16

回答

0

您是否嘗試過使用position: fixed#Wrapper

#wrapper{ 
 
    position: fixed; 
 
    top: 0; 
 
    bottom: 0; 
 
    right: 0; 
 
    left: 0; 
 
    background: greenyellow; 
 
} 
 

 
#left{ 
 
    background: red; 
 
    position: fixed; 
 
    left: 0; 
 
    top: 0; 
 
    height: 100%; 
 
    right: 100px; 
 
} 
 

 
#right{ 
 
    background: blue; 
 
    position: fixed; 
 
    width: 100px; 
 
    top: 0; 
 
    height: 100%; 
 
    right: 0px; 
 
    bottom: 0px 
 
}

上面就是我

+0

不幸的是它不工作。 – Trace 2014-10-11 05:33:04

+0

我需要的是藍色部分具有屏幕的剩餘寬度。這非常重要,因爲Google Map不應該低於正確的div。這會給我帶來麻煩... – Trace 2014-10-11 05:45:15

+0

嘗試新編輯中的代碼 – 2014-10-11 05:45:22