Flex 아이템의 배열 방향 정하는 속성 - flex-direction

플렉스 컨테이너를 지정했다면 플렉스 항목을 배치할 방향을 알려주어야 합니다. flex-direction 속성을 사용해 플렉스 항목의 주축을 가로(row)로 할지, 세로(column)로 할지 지정합니다.
2 min read

flex-direction

플렉스 컨테이너를 지정했다면 플렉스 항목을 배열할 방향을 알려주어야 합니다. flex-direction 속성을 사용해 플렉스 항목의 주축을 가로(row)로 할지, 세로(column)로 할지 지정합니다.

 

기본형

flex-direction : row | row-reverse | column | column-reverse
  • row : 왼쪽에서 오른쪽으로 배열합니다.
  • row-reverse : 오른쪽에서 왼쪽으로 배열합니다.
  • column : 위쪽에서 아래쪽으로 배열합니다.
  • column-reverse : 아래쪽에서 위쪽으로 배열합니다.

flex-direction: row

기본 값은 row로, 왼쪽에서 오른쪽으로 배열합니다.

<div class="container">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
  <div class="item">Item 4</div>
</div>
.container {
  height: 300px;
  padding: 8px;
  background-color: #1e1e1e;
  display: flex;
  flex-direction: row;
}
.item {
  margin: 8px;
  padding: 16px;
  background-color: #b5cea8;
}

 

flex-direction: row-reverse

flex-direction 속성 값을 row-reverse로 하면, 오른쪽에서 왼쪽으로 배열합니다.

.container {
  height: 300px;
  padding: 8px;
  background-color: #1e1e1e;
  display: flex;
  flex-direction: row-reverse;
}

 

flex-direction: column

flex-direction의 값을 column 으로 하면, 위에서 아래로 배열합니다.

.container {
  height: 400px;
  padding: 8px;
  background-color: #1e1e1e;
  display: flex;
  flex-direction: column;
}

 

flex-direction: column-reverse

flex-direction의 값을 column-reverse으로 하면, 아래에서 위로 배열합니다.

.container {
  height: 400px;
  padding: 8px;
  background-color: #1e1e1e;
  display: flex;
  flex-direction: column-reverse;
}

 

 

기타 CSS 참조

You may like these posts

  • justify-content justify-content는 flex-direction으로 정한 방향으로의 정렬을 정합니다. 예를 들어 flex-direction의 값이 row라면 가로 방향의 정렬을 정하고 flex-direction의 값이 column이라면 세로 방향의 정렬을 정합니다.   …
  • 플렉스 박스 레이아웃을 만들려면 먼저 웹 콘텐츠를 플렉스 컨테이너로 묶어주어야 합니다. 즉, 배치하려는 웹 요소들이 있다면 그 요소들을 감싸는 부모 요소를 만들고 그 부모 요소를 플렉스 컨테이너로 만들어야 합니다. 이때 특정 요소가 플렉스 컨테이너로 동작하려면 display 속성을 이용해 플렉스 박스 형태…
  • order 플렉스 아이템은 입력한 순서대로 배치되지만 order 속성으로 플렉스 아이템의 순서를 정할 수 있습니다. 다음 예제는 1번 아이템, 2번 아이템, 3번 아이템이 소스 코드에 입력한 순서대로 출력됩니다. <div class=…
  • align-content flex-wrap 속성의 값이 wrap인 경우, 아이템들의 가로폭의 합이 콘테이너의 가로폭을 넘어가면 아이템이 다음 줄로 내려갑니다. 이때 여러 줄이 되어버린 아이템들의 정렬을 어떻게 할지 정하는 속성이 align-content입니다.   기본형 justif…
  • flex-direction 플렉스 컨테이너를 지정했다면 플렉스 항목을 배열할 방향을 알려주어야 합니다. flex-direction 속성을 사용해 플렉스 항목의 주축을 가로(row)로 할지, 세로(column)로 할지 지정합니다.   기본형 flex-direction : row | r…
  • flex-wrap 기본적으로 플렉스 컨테이너 안의 플렉스 아이템들은 한 줄로 배치됩니다. 하지만 flex-wrap 속성을 사용하면 여러 줄로 배치할 수 있습니다.   기본형 flex-wrap : nowrap | warp | warp-reverse nowrap : 한 줄로 배열합…

Post a Comment