2017-03-10 2 views
2

다양한 화면 크기에 응답하는 플렉스 박스를 사용하여 그리드를 만들고 싶습니다. 휴대 전화에서 세로 방향으로 그리드를 한 열에 만 표시하고자합니다. 가로 방향의 모바일에 대해서는 그리드가 두 개의 열로 바뀌고 그리드가 한 열에서와 동일한 순서를 유지하도록하고 싶습니다. 데스크톱의 경우 그리드가 각각 3 개의 열이있는 3 개의 행이되어야합니다.중첩 된 flexbox 그리드에서 플렉스 방향이 작동하지 않습니다.

지금까지 두 열 레이아웃에서 세 개의 플렉스 박스 세트마다 빈 공간이 생성되었습니다. 나는 그 공간을 채우기 위해 다음 flexbox를 원하고 누군가가 이것을 달성하는데 나를 도울 수 있기를 바랬다.

/* 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는 플렉스 컨테이너

enter image description here

코드 : 여기

내가 (바탕 화면)를 복제하고있는 무슨의 화면 캡처입니다 . 그것은 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

이는 틀에 얽매이지의 솔루션이 될 수 있습니다하지만 난 자들을 위의 용기에 이동하는 데 필요한 상자의 중복을 추가 기본적으로 숨겨져 있습니다. 레이아웃이 두 ​​개의 열로 이동하면 숨겨진 것을 표시하고 원래 상자를 숨 깁니다. 문제 해결됨.

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) { 



} 
관련 문제