2013-03-21 85 views
0

我想在他的parant div的底部不斷放置一個div元素。把一個div放在父div的底部

這應該與

position:relative; 
bottom:0px; 

反正它不中,只想到我所能爲保證金頂部,直到它適合,但我不喜歡這一點。你能在我的代碼中找到一個理由,爲什麼這個相對位置不工作?

@charset "utf-8"; 
/* CSS Document */ 

body { 
    background-color:#999; 
} 

#wrapper { 
    height:40em; 
    max-height:45em; 
    min-height:40em; 
    width:80%; 
    max-width:60em; 
    min-width:30em; 
    margin-left:auto; 
    margin-right:auto; 
    background-color:#333; 
    border:#000 solid; 
    border-width:thin; 
} 

#header { 
    width:100%; 
    height:70px; 
    background-color:#009900; 
    border-bot:#000 solid; 
    border-width:thin; 
} 

#content { 
    position:relative; 
    bottom:0px; 
    top:auto; 
    width:100%; 
    height:30em; 
    background-color:#FFFFFF; 
    border-top:#000 solid; 
    border-width:thin; 
} 

內容和標題都是包裝的父項。所以我想把內容放在包裝的底部。

回答

2

將位置#wrapper設置爲relative,然後將#content的位置設置爲絕對,並將bottom設置爲零。

2

父元素應該有一個position:relative和一個堅持底部

position:absolute; 
bottom:0px; 

希望這會有所幫助。