2010-05-06 95 views
3

我將div的位置設置爲絕對,並且我想將另一個div放在下面。
兩個div具有不同的寬度。
上面的div是絕對位置,並居中。應該在底部的div具有100%的寬度。
如何做到這一點?
謝謝!將div div粘貼到頁面底部

+0

你找到答案嗎? – JoePasq 2011-06-06 16:06:13

回答

2
  • 做一個div同時包含
  • 使用float:right

例如

div#p8015buttons { 
    position:absolute; 
    bottom:0.5em; 
    right:0.5em; 
    width:90px; 
} 
div.p8015 { 
    float:right; 
    margin:1px; 
} 
+1

也就是說,一個絕對定位的容器'div',其中兩個'div's是靜態定位的(他們將會堆疊)。 – Dan 2010-05-06 09:56:31

+0

他們有不同的寬度。底部div應該是整個屏幕的寬度,但上面的div是絕對的並且居中。 – Jack 2010-05-06 09:58:00

+0

它會工作,只要做到這一點,相信我。 (ps:增加例子) – 2010-05-06 10:34:02

0

裹在第三個和位置都的DIV是一個絕對的,而不是原來的一。

0

未經測試,但應該這樣做。

HTML:

<div class="wrapper"> 
     <div class="one"> 
     Content 
     </div> 
     <div class="two"> 
     More content 
     </div> 
    </div> 

而CSS:

.wrapper 
    { 
     position:absolute; 
     width: 500px; 
     height: 400px;/*whatever you want*/ 
     } 

    .one, 
    .two 
    { 
     position:relative; /*or static*/ 
    } 

希望它能幫助:)

0

測試 HTML標記

<div class="wrapper"> 
<div class="left-ontent> 
</div> 
<div class="right-ontent> 
</div> 
</div> 

CSS

.wrapper{width:980px;margin:0 auto;position:absolute;} 
.left-content{float:left;width:630px;} 
.right-content{float:right;width:320px;} 
+0

這個想法是有兩個不同寬度的div與絕對位置。以固定寬度爲中心,另一個沒有智慧(應該像屏幕一樣寬),第二個div應該在第一個下面。 – Jack 2010-05-06 10:31:58

0

試試這個,你就可以移動的風格你的CSS

<div style="width:500px; margin: auto; height:200px; background-color:black;"> 
</div> 
<div style="width:100%; height:200px; background-color:green;"> 
</div> 
+0

沒有像float:center這樣的東西。 http://www.w3schools.com/css/pr_class_float.asp – Kyle 2010-05-06 11:22:04

+1

對不起,我把注意力集中在第一格。編輯! – Mauro 2010-05-06 11:30:31