2013-04-05 83 views
0

我有這樣的代碼使得與汽車利潤率的div父DIV與可變高度

<div style="position: relative;"> 
    /***main***/ 

    <div style="top:0"> 
     /*****Content1****/ 
    </div> 

    <div> 
     /*****Content2****/ 
    </div> 

    <div> 
     /*****Content2****/ 
    </div> 

    <div style="bottom:0"> 
     /*****Content4****/ 
    </div> 

</div> 

我想總是在頂部和content4總是在底部內容1,也希望內容2和content3同樣調整上下頁邊距,使它看起來甚至,我無法做到這一點,因爲父div是可變高度,所有其他div是固定高度。

我認爲這將有助於你理解我想 http://www.spoiledagent.com/ads/Help.jpg

請幫助一下,

+1

你有一個樣式表還是你從無到有? – 2013-04-05 20:36:04

+0

You van訪問網站 http://www.spoiledagent.com/ 我已經在右側使用了這個,你可以看到它正在創建什麼混亂 – Hanumendra 2013-04-05 20:37:42

+0

嘗試添加「position:absolute;」同時包含Content1和Content4的div。 – mkoistinen 2013-04-05 20:40:00

回答

0

你可以試試這個:

http://jsfiddle.net/Q4XaQ/

<div id="main"> 
    <div id="content1">/*****Content1****/</div> 
    <div id="content2">/*****Content2****/</div> 
    <div id="content3">/*****Content3****/</div> 
    <div id="bottom">/*****Content4****/</div> 
</div> 

#main{ 
    margin: 0 auto; 
    width: 960px; 
    background: red; 
} 

#content1{ 
    height: 80px; 
    background: gray; 
} 

#content2{ 
    width:480px; 
    height: 300px; 
    float: left; 
    background: yellow; 
} 

#content3{ 
    width:480px; 
    height: 300px; 
    float: right; 
    background: brown; 
} 

#bottom{ 
    height: 50px; 
    clear:both; 
    background: blue;; 
} 
+0

content1,content2,content3和content4是一個在另一個之下,主要在不同頁面上具有可變高度,但所有寬度均爲250px – Hanumendra 2013-04-05 20:49:50

+0

我認爲這將幫助您理解我想要的 http://www.spoiledagent.com /ads/Help.jpg – Hanumendra 2013-04-05 20:56:16

+0

在這種情況下,您必須使用%代替px。但原理是一樣的。 – 2013-04-05 20:58:33