2016-02-11 171 views

回答

16

給容器:

display:flex; 
flex-direction:column; 

和用於元素:

flex:1; 

演示: https://jsfiddle.net/ugjfwbg4/1/

body { 
 
    background-color: red; 
 
    height: 100%; 
 
} 
 

 
.wrap { 
 
    height: 100vh; 
 
    width: 100%; 
 
    padding: 20px; 
 
    background-color: yellow; 
 
    display:flex; 
 
    flex-direction:column; 
 
} 
 

 
.top { 
 
    width: 100%; 
 
    height: 50px; 
 
    background-color: blue; 
 
} 
 

 
.mid { 
 
    width: 100%; 
 
    background-color: green; 
 
    flex:1; 
 
    display:flex; 
 
    flex-direction:column; 
 
} 
 

 
.left{ 
 
    flex:1; 
 
    width: 50%; 
 
    background-color: red; 
 
} 
 

 
.bottom { 
 
    width: 100%; 
 
    height: 50px; 
 
    background-color: blue; 
 
}
<div class="wrap"> 
 
    <div class="top"></div> 
 

 
    <div class="mid"> 
 
    
 
    <div class="left">left</div> 
 
    </div> 
 

 
    <div class="bottom"></div> 
 
</div>

+0

謝謝約翰。在這個小提琴上:[link](https://jsfiddle.net/ugjfwbg4/2/)綠色的紅色div不能伸展到100%,你能解釋一下嗎? –

+0

像以前一樣按照css規則給容器和孩子。 https://jsfiddle.net/ugjfwbg4/3/並查看https://css-tricks.com/snippets/css/a-guide-to-flexbox/ – John