flex container 속성 : flex-direction, flex-wrap, justify-content, align-items, align-center
flex item 속성 : flex, flex-grow, flex-shrink, flex-basis, order
선택자 { display: flex; }
아래 참고 링크 티스토리 게시물


flex-direction을 사용하여 주축 방향을 변경할 수 있다.row : 주축이 좌 -> 우 방향으로 지정된다column : 주축이 상 -> 하 방향으로 지정된다.row-reverse처럼 reverse를 붙이면 역방향으로 바뀐다.위와 같이 전체적인 흐름은 부모 요소에서 지정하고, 크기나 순서, 위치 등의 속성은 자식 요소에서 지정한다.
flex-container {
display: flex;
flex-direction: row | column;
}

wrap : 자식 요소들의 가로 길이가 부모 영역에 맞춰지지 않고 지정한 크기대로 출력, 부모의 크기보다 넘치면 아래로 줄바꿈(여러 행으로 표시)nowrap : 자식 요소들의 크기가 부모 영역에 맞춰져 한 줄에 배치됨.위와 같이 전체적인 흐름은 부모 요소에서 지정하고, 크기나 순서, 위치 등의 속성은 자식 요소에서 지정한다.
flex-container {
display: flex;
flex-direction: row | column;
flex-wrap: wrap | nowrap;
}
/* 예시 */
.b3 {
width: 400px; height: auto;
flex-wrap: wrap;
}
.b3 > div { width: 200px; height: 100px; }
/* flex 같은 크기로 여러줄로 나타내기 */
.list { display: flex; flex-wrap: wrap; }
.list li { width: 33.33%; }
wrap
nowrap
justify-content : 주축을 기준으로 요소를 정렬
flex-start : 주축의 시작 지점을 기준으로 정렬flex-end : 주축이 끝나는 지점 (주축의 끝부분)을 기준으로 정렬center : 주축의 중앙을 기준으로 정렬 (중앙에 배치)space-between : 요소 사이에 동일하게 여백을 주어 떨어뜨림 (첫번째 item은 주축 시작점에, 마지막 item은 주축 끝지점에 무조건 정렬됨)space-around : 요소 좌우에 동일하게 여백을 주어 떨어뜨린다. (padding같은느낌?), 주축을 기준으로 일정한 간격으로 정렬space-evenly : 요소 뿐만 아니라 양 끝의 여백도 동일하게 떨어뜨림
flex-container {
display: flex;
flex-direction: row | column;
flex-wrap: wrap | nowrap;
justify-content: flex-start | flex-end | center | space-between | space-around;
}
/* 예시 */
.c1 { justify-content: flex-end; }
.c2 { justify-content: center; }
.c3 { justify-content: space-between; }
.c4 { justify-content: space-around; }

stretch : 기본값. flex item의 높이를 늘려 flex container의 전체 높이를 채움flex-start : 교차축 시작 부분을 기준으로 정렬flex-end : 교차축이 끝나는 지점 (끝부분)을 기준으로 정렬center : 교차축의 중앙을 기준으로 정렬 (중앙에 배치)space-between : 요소 사이에 동일하게 여백을 주어 떨어뜨림 (첫번째 item은 교차축 시작점에, 마지막 item은 교차축 끝지점에 무조건 정렬됨)space-around : 교차축을 기준으로 flex item을 일정한 간격으로 정렬
flex-container {
display: flex;
flex-direction: row | column;
flex-wrap: wrap | nowrap;
justify-content: flex-start | flex-end | center | space-between | space-around;
}
/* 예시 */
.c1 { justify-content: flex-end; }
.c2 { justify-content: center; }
.c3 { justify-content: space-between; }
.c4 { justify-content: space-around; }
stretch : 기본값. flex item의 높이를 늘려 flex container의 전체 높이를 채움flex-start : 교차축 시작 지점을 기준으로 정렬flex-end : 교차축이 끝나는 지점 (끝부분)을 기준으로 정렬center : 교차축의 중앙을 기준으로 정렬 (중앙에 배치)baseline : 글꼴의 기준선인 baseline을 기준으로 정렬flex-end : 교차축의 끝부분을 기준으로 정렬
flex-container {
display: flex;
flex-direction: row | column;
flex-wrap: wrap | nowrap;
justify-content: flex-start | flex-end | center | space-between | space-around;
align-items: stretch | flex-start | flex-end | center | baseline | flex-end
}
/* 예시 */
.c5 {
height: 300px;
align-items: center;
}

flex-grow, flex-shrink, flex-basis 세 가지를 축약한 것이다.flex-grow : 속성값이 0이면 크기가 커져도 flex item의 크기가 커지지 않고 원래 크기를 유지. 속성값이 1 이상이면 원래 크기에 상관 없이 flex container를 채우도록 함
flex-shrink : 속성값이 0이면 부모 요소인 flex container의 크기가 커지거나 작아져도 원래 크기를 유지. 속성값이 1 이상이면 flex container의 크기가 flex item의 크기보다 작아지면 item의 크기가 container에 맞게 줄어듦
flex-basis : flex item의 기본 크기(넓이) 설정. 모든 단위를 속성값에 사용할 수 있으며, 단위에 맞게 크기가 고정됨
flex-item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
/*축약*/
flex: 1;
flex: 1 1 0;
}