2011-01-19 239 views
0

我看過很多問題,但沒有一個能夠完全解決我的問題。固定大小的div位於主屏幕右側,填滿屏幕的其餘部分

我有兩個div:mainbody和rightpanel。我希望rightpanel的大小是固定的(210px),並且坐在主體div的右側,它填滿了窗口的所有剩餘空間。

因此,這將調整如下:

+----------------------------------------+ 
|        |   | 
|        |   | 
|        |   | 
|  mainbody    |rightpanel| 
|        |   | 
|        |   | 
|        |   | 
+----------------------------------------+ 

+-------------------------------+ 
|     |   | 
|     |   | 
|     |   | 
| mainbody   |rightpanel| 
|     |   | 
|     |   | 
|     |   | 
+-------------------------------+ 

我整理以下的作品目前的解決方案,但如果窗口下方約900px調整到合適的欄上得到被推到了底部,25%的剩餘空間它太小以至於無法裝入,所以我強制窗口以此寬度水平滾動。

#wrap { 
    width:97%; 
    margin:0 auto; 
} 

#mainbody { 
    float:left; 
    width: 75%; 
    margin-right: 10px; 
    margin-left: 10px; 
} 

#rightpanel { 
    float:right; 
    width: 22%; 
    min-width: 210px; 
    max-width: 210px; 
} 
+0

http://www.dynamicdrive.com/style/layouts/item/css-liquid-layout-22-fluid-fixed/ – sunn0 2011-01-19 10:17:19

+0

@ sunn0這正是我一直在尋找的,它似乎應該工作,但是右側面板仍然被推到主體下方,所以-210px位實際上是在我使用這種佈局時將屏幕推向左側! – lukeo05 2011-01-19 10:29:02

回答

2

,如果你浮起來你需要把右面板的主要內容之前:

<div id="rightpanel">blah blah blah</div> 
<div id="mainbody">blah blah blah 
    blah blah blah 
    blah blah blah 
</div> 

<style type="text/css"> 
    #rightpanel { 
     width:210px; 
     float:right; 
     background-color:red; 
    } 
    #mainbody { 
     margin-right:210px; 
     background-color:blue; 
    } 
</style> 

即使調整了頁面大小,這也可以保持右側面板正確對齊。

0
#mainbody { 
float: left; 
} 
#rightpanel { 
width: 210px; 
} 

你有沒有嘗試過這樣的事情?

+0

這使得主體填充頁面的整個寬度,右側面板位於頁面左側,位於主體後面,儘管它被拉伸以便內容被推到主體完成的位置。 – lukeo05 2011-01-19 10:15:39

1

這應該工作在我的網站

<div id="container"> 
    <div id="left" style="background: #ff00ff; "> 
     Left 
     <div id="right" style="width: 210px; float: right; background: #ff0000;"> 
      Right 
     </div> 
    </div> 
</div> 
+0

這一個讓左邊填滿窗口的整個寬度,右邊被壓到左邊下面,坐在窗口的右邊,但是從頁面底部開始! – lukeo05 2011-01-19 10:14:30

0

看:http://www.mcohenlawyer.com/
是你想要的嗎?

如果是,這是CSS代碼:
(在所有主要的瀏覽器都支持)

div.menubar { 
    position: fixed; /*can be absolute too*/ 
    width: 158px; 
    /*what comes latter is not relevant for your question*/ 
    /*......*/ 
} 
.body { /*the main body*/ 
    position: absolute; 
    right: 180px;/*can be 159px, if you don't want space between divs*/ 
    min-height: 870px; 
    /*what comes latter is not relevant for your question*/ 
    /*......*/ 
} 
+0

這正是我想要的,但是你的CSS讓右面板剛好位於主體頂部屏幕的左側。我開始覺得在我的頁面中必須有其他東西讓它搞砸,因爲這些解決方案都沒有工作,我認爲它們應該是! – lukeo05 2011-01-19 10:30:32

相關問題