2017-06-09 63 views
-3

enter image description here是否可以使用flex構建以下佈局而不嵌套?

例子:

是否有可能建造這種使用Flex佈局不築巢?純粹的,像這樣的結構:

<div class="long"> 
</div> 

<div class="short"> 
</div> 

<div class="short"> 
</div> 

<div class="short"> 
</div> 

<div class="short"> 
</div> 
+0

如果你想框來動態調整內容,沒有劇本,然後沒有。 – LGSon

+0

使用flexbox時,如果您可以在容器上設置固定高度,則可以。 https://stackoverflow.com/q/34480760/3597276 –

回答

1

當然。見下面

* { 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    display: flex; 
 
    flex-flow: column; 
 
    flex-wrap: wrap; 
 
    max-height: 200px; 
 
    max-width: 320px; 
 
} 
 

 
.long { 
 
    background-color: red; 
 
    border: thin solid darkgray; 
 
    width: 100px; 
 
    height: 200px; 
 
} 
 

 
.short { 
 
    background-color: blue; 
 
    border: thin solid darkgray; 
 
    width: 100px; 
 
    height: 100px; 
 
}
<div class="container"> 
 
    <div class="long"></div> 
 
    <div class="short"></div> 
 
    <div class="short"></div> 
 
    <div class="short"></div> 
 
    <div class="short"></div> 
 
</div>

*

+0

謝謝!一個問題:爲什麼彩色divs之間有巨大的空間? – alex

+1

這是因爲默認情況下,容器div的寬度爲100%。我現在已經在代碼中定義了最大寬度來減少div之間的空間。 – Gerard

相關問題