2017-08-01 62 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