Flex Container
의 Flex Item
들을 설정된 속성에 따라 배치하는 레이아웃 배치 전용 기능<style>
.container{
display: flex; /* 이 설정을 통해 Flex Item 들이 flex 설정의 영향을 받음 */
}
</style>
...
<div class="container">
<div class="item1"> ITEM1 </div>
<div class="item2"> ITEM2 </div>
<div class="item3"> ITEM3 </div>
<div class="item4"> ITEM4 </div>
</div>
Flex Container
Flex
의 영향을 받는 전체 공간.display
flex-direction
flex-wrap
flex-flow
justify-content
align-tiems
align-content
Flex Item
div
flex-basis
flex-grow
flex-shrink
flex
align-self
order
z-index
Flex Container
에 적용하는 속성들display
display:flex
혹은 display: inline-flex
적용시 Flex Item 들은 가로 방향으로 배치된다. display: flex
컨테이너가 Block 요소와 같은 성향(수직 쌓임)
을 가짐.display: inline-flex
: 컨테이너가 Inline 요소와 같은 성향(수평 쌓임)
을 가짐Flex Item
width
: 내부 요소의 width
Flex Item
height
: 컨테이너의 height
flex-direction
Flex Item
의 메인 축 (Main-Axis) 설정flex-wrap
Flex Item
의 줄 바꿈(줄 묶음) 설정flex-flow
flex-direction
과 flex-wrap
을 동시에 설정.flex-flow: row wrap;
justify-content
flex-start
default : 메인 축 시작점 정렬
flex-end
: 메인 축 끝점 정렬
center
: 메인 축 가운데 정렬
space-between
: 시작점과 끝점에 배치 후 균일한 간격으로 배치됨
space-around
: 모든 Item
이 동일한 간격으로 배치됨
space-evenly
: 동일한 양 끝 간격과 사이 간격으로 배치됨
align-tiems
Items
의 정렬 방법 설정stretch
default : 교차 축을 채우기 위해 Items
를 늘림flex-start
: 교차 축 시작점 정렬flex-end
: 교차 축 끝점 정렬center
: 교차 축 가운데 정렬base-line
: 텍스트 베이스라인 기준으로 정렬align-content
flex-wrap: wrap;
or flex-wrap: wrap-reverse;
설정이 되어있어야함 stretch
default : 교차 축을 채우기 위해 Items
를 늘림flex-start
: 교차 축 시작점 정렬flex-end
: 교차 축 끝점 정렬center
: 교차 축 가운데 정렬space-between
: 교차 축 시작점과 끝점에 배치 후 균일한 간격으로 배치됨space-around
: 교차 축 기준 모든 Item
이 동일한 간격으로 배치됨Flex Item
에 적용하는 속성들order
Item
의 순서를 설정flex-grow
Item
의 증가 너비 비율을 설정flex-grow
의 값의 비율 만큼 너비가 늘어남<style>
.item1 { flex-grow: 1; }
.item2 { flex-grow: 1; }
.item3 { flex-grow: 2; }
</style>
flex-shrink
Item
의 감소 너비 비율을 설정0
으로 설정한 경우 flex-basis보다 작아지지 않기 때문에 고정폭의 컬럼을 만들수 있다.flex-shrink
의 값의 비율 만큼 너비가 줄어듬<style>
.container { width: 700px; padding: 20px; }
.item1 { flex-basis: 150px; flex-shrink: 1; }
.item2 { flex-basis: 250px; flex-shrink: 2; }
.item3 { flex-basis: 350px; flex-shrink: 3; }
</style>
flex-basis
Item
의 공간 배분 전 기본 너비를 설정auto
일 경우 width
height
등의 속성으로 너비를 설정할 수 있다.px
em
rem
등flex
flex-grow
flex-shrink
flex-basis
를 설정하는 단축 속성flex: 0 1 auto;
flex-shrink
flex-basis
생략 가능align-self
Item
의 정렬 방법 설정Conatinaer
의 align-items
보다 우선함auto
default : Container
의 align-items
속성을 상속받음stretch
: 교차 축을 채우기 위해 Items
를 늘림flex-start
: 교차 축 시작점 정렬flex-end
: 교차 축 끝점 정렬center
: 교차 축 가운데 정렬base-line
: 텍스트 베이스라인 기준으로 정렬
아주 유용한 정보네요!