2017-08-01 63 views
1

試圖做一個帶有header,body和footer的柱狀柔性盒,然後在體內有兩個並排的尊重柔性盒邊界的div(即don不會溢出頁腳)。flex-flow column with side-by-side divs in body

html, 
body { 
    height: 100%; 
    margin: 0; 
} 

.app { 
    display: flex; 
    flex-flow: column; 
    height: 100%; 
} 

.header { 
    flex: 0 1 auto; 
    border-style: solid; 
    border-width: 1px; 
    border-color: blue; 
} 

.body { 
    display: flex; 
    flex-flow: column; 
    flex: 1 1 auto; 
    overflow-y: auto; 
    border-style: solid; 
    border-width: 1px; 
    border-color: red; 
} 

.footer { 
    flex: 0 1 40px; 
    border-style: solid; 
    border-width: 1px; 
    border-color: green; 
} 

.inner { 
    position: absolute; 
} 
.left { 
    float: left; 
    width: 200px; 
    height: 100%; 
} 

.right { 
    margin-left: 225px; 
    height: 100%; 
} 

簡單的測試案例中的jsfiddle

<div class='app'> 
    <div class='header'> 
    <p><b>header</b> 
     <br /> 
     <br />(sized to content)</p> 
    </div> 
    <div class='body'> 
    <div class='inner'> 

     <div class='left'> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     <p>test 1</p> 
     </div> 
     <div class='right'> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     <p>test 2</p> 
     </div> 
    </div> 

    </div> 
    <div class='footer'> 
    <p><b>footer</b> (fixed height)</p> 
    </div> 
</div> 

https://jsfiddle.net/XJ45G19/9e7vjykv/

enter image description here

任何想法,我要去哪裏錯了嗎?提前致謝!

+0

不確定你確切的問題是什麼,但是當你從'.inner'中刪除'position:absolute'時出了什麼問題? –

+0

arg!謝謝喬。我覺得很愚蠢。如果你想發佈這個答案,我會很樂意接受它。並再次感謝您的幫助。 – shaz

+0

哈哈,沒問題。 –

回答

1

發帖:

.inner刪除position: absolute

1

中間.body元素沒有溢出,因爲內容已被絕對定位,這會將其從正常流程中移除。

.inner中刪除position: absolute後,內容佔用空間,垂直滾動條彈出.body。作爲回答每個請求

+1

謝謝Michael。我想給喬第一槍,但我很欣賞這種迴應 – shaz