Flex-direction으로 방향 지정한 아이템 배열 방법 - justify-content

justify-content 속성은 flex-direction 속성으로 정한 방향으로의 정렬을 정합니다. 예를 들어 flex-direction의 값이 row라면 가로 방향의 정렬을 정하고 flex-direction의 값이 column이라면 세로 방향의 정렬을 정합니다.
4 min read

justify-content

justify-content는 flex-direction으로 정한 방향으로의 정렬을 정합니다. 예를 들어 flex-direction의 값이 row라면 가로 방향의 정렬을 정하고 flex-direction의 값이 column이라면 세로 방향의 정렬을 정합니다.

 

기본형

justify-content : flex-start | flex-end | center | space-between | space-around | space-evenly
  • flex-start : 시작점부터 아이템을 배치합니다.
  • flex-end : 종료점부터 아이템을 배치합니다.
  • center : 가운데에 아이템을 배치합니다.
  • space-between : 아이템을 시작점과 종료점에 붙이고, 나머지 빈 공간을 균등하게 나누어 배치합니다.
  • space-around : 빈 공간을 균등하게 배치하되, 아이템 사이의 간격은 양끝 간격의 두 배가 됩니다.
  • space-evenly : 아이템 사이의 간격을 균등하게 배치합니다.

 

justify-content: flex-start

justify-content의 기본값은 flex-start로 시작점부터 아이템을 배치합니다.

<div class="container">
  <div class="item">Item 1</div>
  <div class="item">Item 2 Item 2</div>
  <div class="item">Item 3 Item 3 Item 3</div>
</div>
.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: flex-start;
  flex-direction: row;
}
.item:nth-child(1) {
  background-color: #ffebee;
}
.item:nth-child(2) {
  background-color: #ffcdd2;
}
.item:nth-child(3) {
  background-color: #ef9a9a;
}

 

justify-content: flex-start 일 때 flex-direction: row-reverse 로 정하면 플렉스 시작점이 오른쪽이 됩니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: flex-start;
  flex-direction: row-reverse;
}

justify-content: flex-start 일 때 flex-direction: column 로 정하면 플렉스 시작점이 위쪽이 됩니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
}

 

justify-content: flex-start 일 때 flex-direction: column-reverse 로 정하면 플렉스 시작점이 아래쪽이 됩니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: flex-start;
  flex-direction: column-reverse;
}

 

justify-content: flex-end

justify-content의 값을 flex-end로 정하면 플렉스가 끝나는 지점에 배치합니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: flex-end;
}

 

justify-content: center

justify-content의 값을 center로 정하면 가운데에 배치합니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: center;
}

 

justify-content: space-between

justify-content의 값을 space-between으로 정하면 빈 공간을 균등하게 나누어 아이템 사이에 간격을 만듭니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: space-between;
}

 

justify-content: space-around

justify-content의 값을 space-around로 정하면 양 옆의 간격을 균등하게 만듭니다. 아이템 사이의 간격은 양끝 간격의 두 배가 됩니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: space-around;
}

 

justify-content: space-evenly

justify-content의 값을 space-evenly로 정하면 양끝과 아이템 사이의 간격을 동일하게 만듭니다.

.container {
  height: 400px;
  background-color: #01579b;
  display: flex;
  justify-content: space-evenly;
}

 

 

기타 CSS 참조

You may like these posts

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

Post a Comment