2017-01-19 6 views
0

Iは、以下に示すように(AとB)は、2つのdivを有する:CSS DIV動的高

enter image description here

セクションBされる(例として)100ピクセルの最大高さと入力フィールドを有し、overflow- y auto:この方法では、入力フィールドは特定の高さになります。

.section_B{ 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
} 
.section_B_input{ 
    max-height: 100px; 
    overflow-y: auto; 
} 

セクションBの高さは、(例えば)どこ20ピクセルと100ピクセルとの間であることができるので、セクションAの高さが動的であることが必要とセクションBの高さに依存しています。

私はそのディスプレイを読んでいます:フレックスは何とか使うことができますが、どうすればよいかわかりません。

提案がありますか?

ありがとうございます!

答えて

1

フレックスボックスのテクニックは、動的な高さにしたい要素にflex-grow: 1;を追加することです。ここに簡単な例があります。

* {margin:0;padding:0;box-sizing:border-box;} 
 
html,body,.flex { 
 
    min-height: 100vh; 
 
} 
 
.flex { 
 
    display: flex; 
 
    flex-direction: column; 
 
} 
 
.a { 
 
    flex-grow: 1; 
 
    background: #eee; 
 
} 
 
.b { 
 
    background: #333; 
 
} 
 
section { 
 
    padding: 2em; 
 
} 
 
input { 
 
    transition: padding .5s; 
 
} 
 
input:focus { 
 
    padding: 2em; 
 
}
<div class="flex"> 
 
    <section class="a"> 
 
    </section> 
 
    <section class="b"> 
 
    <input> 
 
    </section> 
 
</div>