2017-10-19 153 views
1

我有一個容器divdisplay: table和三個內部的divs有display: table-cell位置在100%寬度的表格單元內的底部div

兩個外部表格單元具有固定寬度,內部表格單元具有width:100%。所以它隨着瀏覽器的大小而變化。

我還有一個頁腳div,我試圖放置在中間單元格的底部,使用width: 100%。但它擴展了中間表格單元的寬度。

這個問題如何解決?

實施例:https://jsfiddle.net/9opnx9r8/

HTML

html, 
 
body { 
 
    height: 100%; 
 
} 
 

 
.cell { 
 
    display: table-cell; 
 
    border: 1px solid red; 
 
} 
 

 
.cell1, 
 
.cell3 { 
 
    min-width: 150px; 
 
} 
 

 
.cell2 { 
 
    width: 100%; 
 
} 
 

 
.text { 
 
    border: 1px solid green; 
 
    position: absolute; 
 
    left: inherit; 
 
    bottom: 0; 
 
    width: 100%; 
 
    height: 70px; 
 
}
<div style="display:table; min-height: 100%;"> 
 
    <div class="cell cell1"> 
 
    <h1>C1</h1> 
 
    </div> 
 
    <div class="cell cell2"> 
 
    <h1>C2</h1> 
 
    <ul> 
 
     <li>List</li> 
 
     <li>must</li> 
 
     <li>stay</li> 
 
     <li>top</li> 
 
    </ul> 
 
    <div class="text">FOOTER TEXT HERE</div> 
 
    </div> 
 
    <div class="cell cell3"> 
 
    <h1>C3</h1> 
 
    </div> 
 
</div>

+0

做你希望它是在底部,或只是在頁面底部的中間容器,但在中間 – Keith

+0

我認爲,所有你需要做的排列是加上'位置:相對於'.cell2「。 – Mark

+0

你只需要刪除位置:絕對的.text類來獲得它在底部的中間容器 – Keith

回答

1

對於絕對定位元素的包含塊是最近的定位的祖先。

如果沒有定位的祖先,則包含塊是視口。

因此,將position: relative添加到應該作爲頁腳包含塊的元素。

html,body { 
 
    height: 100%; 
 
} 
 

 
.cell { 
 
    display: table-cell; 
 
    border: 1px solid red; 
 
} 
 

 
.cell1, .cell3 { 
 
    min-width: 150px; 
 
} 
 

 
.cell2 { 
 
    width: 100%; 
 
    position: relative; /* NEW */ 
 
} 
 

 
.text { 
 
    border: 1px solid green; 
 
    position: absolute; 
 
    left: inherit; 
 
    bottom:0; 
 
    width: 100%; 
 
    height: 70px; 
 
}
<div style="display:table; min-height: 100%;"> 
 
    <div class="cell cell1"> 
 
     <h1>C1</h1> 
 
    </div> 
 
    <div class="cell cell2"> 
 
     <h1>C2</h1> 
 
     <ul> 
 
     <li>List</li> 
 
     <li>must</li> 
 
     <li>stay</li> 
 
     <li>top</li> 
 
     </ul> 
 
     <div class="text">FOOTER TEXT HERE</div> 
 
    </div> 
 
    <div class="cell cell3"> 
 
     <h1>C3</h1> 
 
    </div> 
 
</div>

+0

重疊。但是這會與OP的當前設置產生重疊https://jsfiddle.net/9opnx9r8/1/ – Huangism

+0

@黃色,這是一個單獨的問題。頁腳現在位於應有的位置。問題不在於大小和對齊。 –

+0

這正是我所需要的,重疊是沒有問題的。謝謝。 – Vivendi

相關問題