2016-07-13 7 views
1

2つのdivの内側にフレックスカラムコンテナがあります。最初のdivには残りのスペースが大きくなるようにflex: 1があります。 2番目のdivは固定された高さです。コンテナはビューポート全体を取る固定されたdiv内にあることに注意してください。コンテナが最小サイズに達したときにFlexboxがオーバーフローする

問題は、コンテナがコンテンツに収まるには小さすぎると、最初のdivのコンテンツが2番目のコンテンツの下にオーバーフローすることです。ここで

.test { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    background-color: red; 
 
    width: 100%; 
 
    height: 100%; 
 
    display: flex; 
 
    flex-direction: column; 
 
    //min-height: 500px; 
 
} 
 
.child1 { 
 
    width: 100%; 
 
    display: flex; 
 
    flex-direction: column; 
 
    align-items: center; 
 
    flex: 1; 
 
} 
 
.child2 { 
 
    width: 100%; 
 
    display: flex; 
 
    justify-content: center; 
 
} 
 
span { 
 
    padding: 20px; 
 
} 
 
span:first-child { 
 
    margin-top: auto; 
 
} 
 
span:last-child { 
 
    margin-bottom: auto; 
 
}
<div class="test"> 
 
    <div class="child1"> 
 
    <span>Test1</span> 
 
    <span>Test2</span> 
 
    <span>Test3</span> 
 
    <span>Test4</span> 
 
    <span>Test5</span> 
 
    <span>Test6</span> 
 
    <span>Test7</span> 
 
    <span>Test8</span> 
 
    </div> 
 
    <div class="child2"> 
 
    <span>Test1</span> 
 
    <span>Test2</span> 
 
    <span>Test3</span> 
 
    <span>Test4</span> 
 
    </div> 
 
</div>

codepen exampleです。

1つの解決策は、コンテナの最小高さを設定することですが、動的で応答性の高い解決策ではありません。

コンテンツ全体が収まらないときに、コンテナのオーバーフロー動作を実現する方法を教えてもらえますか?

+0

位置を使用する理由:固定します。 ??原因:http://codepen.io/gc-nomade/full/jAaoGQ//http://codepen.io/gc-nomade/pen/jAaoGQは正常です.... –

+0

@GCyrillus 'position:fixed'は次のとおりです。私の重なり合ったメニューのために。私はすべてが自分のプロジェクトに似ていることを確認しています。 – Simon

+0

大丈夫です、そしてそれを修正するオーバーフローを追加し、フレックス値(chromeを含む)を更新してください。http://codepen.io/gc-nomade/pen/EybzpV –

答えて

3

あなたは.testoverflow:autoを追加し、.child1flex値を更新することがあります。DEMO to play with

.test { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    background-color: red; 
 
    width: 100%; 
 
    height: 100%; 
 
    display: flex; 
 
    flex-direction: column; 
 
    overflow:auto;/* update */ 
 
} 
 

 
.child1 { 
 
    width: 100%; 
 
    display: flex; 
 
    flex-direction: column; 
 
    align-items: center; 
 
    justify-content:center;/* update (IE)*/ 
 
    flex: 1 0 auto;/* update *//* flex-shrink:0 allow element to expand and push next container else overflow defaut is visible IF SET TO 1 */ 
 
} 
 

 
.child2 { 
 
    width: 100%; 
 
    display: flex; 
 
    justify-content: center; 
 
} 
 

 
span { 
 
    padding: 20px; 
 
} 
 

 
span:first-child { 
 
    margin-top: auto; 
 
} 
 

 
span:last-child { 
 
    margin-bottom: auto; 
 
}
<div class="test"> 
 
    <div class="child1"> 
 
    <span>Test1</span> 
 
    <span>Test2</span> 
 
    <span>Test3</span> 
 
    <span>Test4</span> 
 
    <span>Test5</span> 
 
    <span>Test6</span> 
 
    <span>Test7</span> 
 
    <span>Test8</span> 
 
    </div> 
 
    <div class="child2"> 
 
    <span>Test1</span> 
 
    <span>Test2</span> 
 
    <span>Test3</span> 
 
    <span>Test4</span> 
 
    </div> 
 
</div>

+0

期待通りに働きました、ありがとう!あなたの答えを編集して 'flex-shrink:0'が問題を解決した理由を説明できますか? – Simon

+0

@SimonはCSSコメントで更新されました/ * flex-shrink:0要素を展開して次のコンテナを押し込むことができましたelse overflow defautが見えるIF SET TO 1 * / –

関連する問題