2017-03-10 12 views
2

さまざまな画面サイズに対応するフレックスボックスを使用してグリッドを作成したいと考えています。縦向きのモバイルでは、グリッドを1列のみにしたいと思います。ランドスケープのモバイルについては、グリッドを2つの列に変えて、グリッドを1つの列と同じ順序に維持したいと思います。デスクトップの場合、グリッドはそれぞれ3つの列で3行になります。ネストされたフレックスボックスグリッドでフレックス方向が機能しない

今のところ、2列のレイアウトでは、3つのフレックスボックスの各セットの後に作成される空きスペースがあります。私は次のフレックスボックスがそのスペースを埋めることを望み、誰かがこれを達成するのを手伝ってくれることを願っていました。ここで

は、私が(デスクトップ)を複製しています何のスクリーンキャプチャです:あなたのコードで

enter image description here

コード

/* CSS Styles for the revised "Our */ 
 

 
/* Extra small devices (phones, less than 768px) */ 
 

 
.work__container { 
 
    height: auto; 
 
    display: flex; 
 
    flex-direction: column; 
 
} 
 

 
.work__flex { 
 
    width: 100vw; 
 
    height: auto; 
 
    display: flex; 
 
    flex-direction: column; 
 
} 
 

 
.work__flex--item { 
 
    width: 100vw; 
 
    height: 100vw; 
 
} 
 

 
.amur {background-color: #F0E5D3;} 
 
.pop-shoes {background-color: #F59390;} 
 
.love-your-linens {background-color: #DADADA;} 
 
.bench {background-color: #B3B3B3;} 
 
.dogpack {background-color: #359DB6;} 
 
.smoke-show {background-color: #426449;} 
 
.roman-coffee-co {background-color: #9A7D2F;} 
 
.protech {background-color: #E2342D;} 
 
.northstone {background-color: #363636;} 
 

 
/* Mobile in landscape orientation */ 
 
@media (max-width: 767px) and (orientation: landscape) { 
 
    
 
.work__flex { 
 
    flex-direction: row; 
 
    flex-wrap: wrap; 
 
} 
 
    
 
.work__flex--item { 
 
    width: 50vw; 
 
    height: 50vw; 
 
} 
 
    
 
    
 
} 
 

 
/* Small devices (tablets, 768px and up) */ 
 
@media (min-width: 768px) { 
 

 
.work__flex { 
 
    flex-direction: row; 
 
    flex-wrap: wrap; 
 
} 
 
    
 
.work__flex--item { 
 
    width: 50vw; 
 
    height: 50vw; 
 
}  
 
    
 
} 
 

 
/* Medium devices (desktops, 992px and up) */ 
 
@media (min-width: 992px) { 
 

 
.work__flex { 
 
    flex-direction: row; 
 
} 
 

 
.work__flex--item { 
 
    width: 33.33vw; 
 
    height: 33.33vw; 
 
} 
 

 
} 
 

 
/* Large devices (large desktops, 1200px and up) */ 
 
@media (min-width: 1200px) { 
 

 
    
 

 
}
<div class="work__container"> 
 
    <div class="work__flex"> 
 
    <div class="work__flex--item one"> 
 
    </div> 
 
    <div class="work__flex--item two"> 
 
    </div> 
 
    <div class="work__flex--item three"> 
 
    </div> 
 
    </div> 
 
    <div class="work__flex"> 
 
    <div class="work__flex--item one"> 
 
    </div> 
 
    <div class="work__flex--item two"> 
 
    </div> 
 
    <div class="work__flex--item three"> 
 
    </div> 
 
    </div> 
 
    <div class="work__flex"> 
 
    <div class="work__flex--item one"> 
 
    </div> 
 
    <div class="work__flex--item two"> 
 
    </div> 
 
    <div class="work__flex--item three"> 
 
    </div> 
 
    </div> 
 
</div>

答えて

2

.work__containerはフレックスコンテナです。それはdisplay: flexです。

しかし、.work__flexは、ではありません。フレックスコンテナです。 display: flexまたはdisplay: inline-flexがありません。

フレックスコンテナにのみ適用されるflex-directionは、.work__flexでは無視されています。同じ理由で、は、.work__flexでも無視されています。ここで

は、より完全な説明です: Proper use of flex properties when nesting flex containers

+1

私による完全な監督。それを指摘してくれてありがとう。 @Michael_B –

1

/* Extra small devices (phones, less than 768px) */ 
 

 
.work__flex { 
 
    height: auto; 
 
    display: flex; 
 
    flex-direction: column; 
 
    margin:2px; 
 
} 
 

 
.work__flex { 
 
    width: 100vw; 
 
    height: auto; 
 
    flex-direction: column; 
 
} 
 

 
.work__flex--item { 
 
    width: 100vw; 
 
    height: 100vw; 
 
} 
 

 
.one { 
 
    background-color: blue; 
 
} 
 

 
.two { 
 
    background-color: red; 
 
} 
 

 
.three { 
 
    background-color: yellow; 
 
} 
 

 

 
/* Mobile in landscape orientation */ 
 

 
@media (max-width: 767px) and (orientation: landscape) { 
 
    .work__flex { 
 
    flex-direction: row; 
 
    flex-wrap: wrap; 
 
    } 
 
    .work__flex--item { 
 
    width: 50vw; 
 
    height: 50vw; 
 
    } 
 
} 
 

 

 
/* Small devices (tablets, 768px and up) */ 
 

 
@media (min-width: 768px) {} 
 

 

 
/* Medium devices (desktops, 992px and up) */ 
 

 
@media (min-width: 992px) { 
 
    .work__flex { 
 
    flex-direction: row; 
 
    } 
 
    .work__flex--item { 
 
    width: 33.33vw; 
 
    height: 33.33vw; 
 
    } 
 
} 
 

 

 
/* Large devices (large desktops, 1200px and up) */ 
 

 
@media (min-width: 1200px) {}
<div class="work__container"> 
 
    <div class="work__flex"> 
 
    <div class="work__flex--item one"> 
 
    </div> 
 
    <div class="work__flex--item two"> 
 
    </div> 
 
    <div class="work__flex--item three"> 
 
    </div> 
 
    </div> 
 
    <div class="work__flex"> 
 
    <div class="work__flex--item one"> 
 
    </div> 
 
    <div class="work__flex--item two"> 
 
    </div> 
 
    <div class="work__flex--item three"> 
 
    </div> 
 
    </div> 
 
    <div class="work__flex"> 
 
    <div class="work__flex--item one"> 
 
    </div> 
 
    <div class="work__flex--item two"> 
 
    </div> 
 
    <div class="work__flex--item three"> 
 
    </div> 
 
    </div> 
 
</div>

0

これは型破りな解決策になるかもしれませんが、私はその上のコンテナに移動するために必要なボックスの重複を追加しましたデフォルトでは隠されています。レイアウトが2つの列になると、隠れたものが表示され、元のボックスは非表示になります。問題が解決しました。

HTML:

<div class="work__container"> 
     <div class="work__flex"> 
      <div class="work__flex--item amur"> 
      </div> 
      <div class="work__flex--item pop-shoes"> 
      </div> 
      <div class="work__flex--item love-your-linens"> 
      </div> 
      <div class="work__flex--item bench hidden"> 
      </div> 
     </div> 
     <div class="work__flex"> 
      <div class="work__flex--item bench duplicate"> 
      </div> 
      <div class="work__flex--item dogpack"> 
      </div> 
      <div class="work__flex--item smoke-show"> 
      </div> 
      <div class="work__flex--item roman-coffee-co hidden"> 
      </div> 
      <div class="work__flex--item protech hidden"> 
      </div> 
     </div> 
     <div class="work__flex"> 
      <div class="work__flex--item roman-coffee-co duplicate"> 
      </div> 
      <div class="work__flex--item protech duplicate"> 
      </div> 
      <div class="work__flex--item northstone"> 
      </div> 
     </div> 
    </div> 

CSS:

/* CSS Styles for the revised "Our Work" page */ 

/* Extra small devices (phones, less than 768px) */ 

.work__container { 
    height: auto; 
    display: flex; 
    flex-direction: column; 
} 

.work__flex { 
    width: 100vw; 
    height: auto; 
    display: flex; 
    flex-direction: column; 
} 

.work__flex--item { 
    width: 100vw; 
    height: 100vw; 
} 

.amur {background-color: #F0E5D3;} 
.pop-shoes {background-color: #F59390;} 
.love-your-linens {background-color: #DADADA;} 
.bench {background-color: #B3B3B3;} 
.dogpack {background-color: #359DB6;} 
.smoke-show {background-color: #426449;} 
.roman-coffee-co {background-color: #9A7D2F;} 
.protech {background-color: #E2342D;} 
.northstone {background-color: #363636;} 

.hidden {display: none;} 

/* Mobile in landscape orientation */ 
@media (max-width: 767px) and (orientation: landscape) { 

.work__flex { 
    flex-direction: row; 
    flex-wrap: wrap; 
} 

.work__flex--item { 
    width: 50vw; 
    height: 50vw; 
} 

.hidden {display: inline !important;} 
.duplicate {display: none !important;} 

} 

/* Small devices (tablets, 768px and up) */ 
@media (min-width: 768px) { 

.work__flex { 
    flex-direction: row; 
    flex-wrap: wrap; 
} 

.work__flex--item { 
    width: 50vw; 
    height: 50vw; 
} 

.hidden {display: inline !important;} 
.duplicate {display: none !important;} 

} 

/* Medium devices (desktops, 992px and up) */ 
@media (min-width: 992px) { 

.work__flex { 
    flex-direction: row; 
} 

.work__flex--item { 
    width: 33.33vw; 
    height: 33.33vw; 
} 

} 

/* Large devices (large desktops, 1200px and up) */ 
@media (min-width: 1200px) { 



} 
関連する問題