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

  • font-size 글자 크기는 font-size 속성으로 조절합니다. 픽셀이나 포인트를 비롯해 크기를 여러 단위로 지정할 수 있고 백분율을 사용할 수도 있습니다.   기본형 font-size : 절대크기 | 상대크기 | 크기 | 백분율   사용 가능한 속성값 font-…
  • 스타일 속성을 적용하는 요소를 '선택자(selector)'라고 부릅니다. 먼저 전체 선택자, 타입 선택자, 속성 선택자를 살펴보겠습니다. 목차 전체 선택자 (Universal Selector) 전체 선택자는 모든 HTML 요소를 선택합니다. 별표( * )로 나타냅니다. 예를 들…
  • 웹 문서에서 사용할 글꼴은 font-family 속성으로 지정합니다. 이 속성은 <body> 태그를 비롯해 <p> 태그나 <h1>, <h2>, <h3> 태그처럼 텍스트를 사용하는 요소들에서 주로 사용합니다. 기본형 font-family :…
  • font-style font-style은 글자 모양을 정하는 속성으로, 기울임 여부를 정합니다.   기본형 font-style : normal | italic | oblique normal : 보통 모양입니다. italic : 기울임꼴입니다. oblique : 기울임꼴입니다. &n…
  • 웹 문서에서 특정 부분에 스타일을 적용하려면 보통 class나 id 선택자를 이용해 이름을 붙여 주고 그 클래스아 id에 대한 스타일을 정의하면 됩니다. 하지만 여러 개의 항목이 일렬(가로나 세로)로 나열되 있는 경우, class나 id를 사용하지 않고 nth-child(n)이나 nth-last-child…
  • color 웹 문서에서 제목이나 문단 등의 텍스트에서 사용되는 글자 색을 바꿀 때는 color 속성을 사용합니다.   기본형 color : 색상 색상 값은 16진수나 rgb(또는 rgba), hsl(또는 hsla) 또는 색상 이름으로 표기할 수 있습니다.   …

Post a Comment