[CSS] 주축 방향 정렬 justify-content 란?

2024. 7. 4. 16:27·CSS

justify-content 속성이란

justify-content 속성은 Flex 컨테이너 내에서 주 축(main axis)을 따라 아이템들을 정렬하는 방법을 정의한다.

  • flex-start: 아이템들을 주 축의 시작 부분에 정렬한다 (기본값).
  • flex-end: 아이템들을 주 축의 끝 부분에 정렬한다
  • center: 아이템들을 주 축의 가운데에 정렬한다
  • space-between: 첫 번째 아이템은 시작 부분에, 마지막 아이템은 끝 부분에 정렬하고, 나머지 아이템들은 사이에 고르게 분포시킨다
  • space-around: 아이템들 주위에 고르게 여백을 분포시킨다 아이템 간의 여백은 동일하지만, 첫 번째 아이템과 마지막 아이템의 바깥 여백은 내부 여백의 절반이다
  • space-evenly: 모든 아이템들을 사이의 여백과 아이템 바깥의 여백이 동일하게 분포되도록 정렬한다

 

1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	.container {
		display: flex;
		border: 2px solid #333;
		margin-bottom: 20px;
		padding: 10px;
	}
	
	.box {
		background-color: #007bff;
		color: white;
		padding: 20px;
		margin: 10px;
		text-align: center;
		border-radius: 5px;
		width: 150px;
	}
	
</style>
</head>
<body>
	<h2>flex-wrap:nowrap(기본값)</h2>
	<div class="container" style="flex-wrap: nowrap;">
		<div class="box">아이템1</div>
		<div class="box">아이템2</div>
		<div class="box">아이템3</div>
		<div class="box">아이템4</div>
		<div class="box">아이템5</div>
		<div class="box">아이템6</div>
		<div class="box">아이템7</div>
	</div>
	
		<h2>flex-wrap:nowrap</h2>
	<div class="container" style="flex-wrap: wrap;">
		<div class="box">아이템1</div>
		<div class="box">아이템2</div>
		<div class="box">아이템3</div>
		<div class="box">아이템4</div>
		<div class="box">아이템5</div>
		<div class="box">아이템6</div>
		<div class="box">아이템7</div>
	</div>
	
		<h2>flex-wrap:nowrap-reverse(기본값)</h2>
	<div class="container" style="flex-wrap: wrap-reverse;">
		<div class="box">아이템1</div>
		<div class="box">아이템2</div>
		<div class="box">아이템3</div>
		<div class="box">아이템4</div>
		<div class="box">아이템5</div>
		<div class="box">아이템6</div>
		<div class="box">아이템7</div>
	</div>
	
</body>
</html>

 

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	.container {
		display: flex;
		border: 2px solid #333;
		margin-bottom: 20px;
		padding: 10px;
		flex-direction: row;
	}
	
	.item {
		background-color: #007bff;
		color: white;
		padding: 20px;
		margin: 10px;
		text-align: center;
		border-radius: 5px;
		width: 150px;
	}

</style>
</head>
<body>
	<h2>justify-content: flex-start(기본값)</h2>
	<div class="container" style="justify-content: flex-start;">
		<div class="item">아이템1</div>
		<div class="item">아이템2</div>
		<div class="item">아이템3</div>
	</div>
	
		<h2>justify-content: flex-end</h2>
	<div class="container" style="justify-content: flex-end;">
		<div class="item">아이템1</div>
		<div class="item">아이템2</div>
		<div class="item">아이템3</div>
	</div>
	
		<h2>justify-content: flex-center</h2>
	<div class="container" style="justify-content: center;">
		<div class="item">아이템1</div>
		<div class="item">아이템2</div>
		<div class="item">아이템3</div>
	</div>
	
	
		<h2>justify-content: space-between</h2>
	<div class="container" style="justify-content:  space-between;">
		<div class="item">아이템1</div>
		<div class="item">아이템2</div>
		<div class="item">아이템3</div>
		<div class="item">아이템4</div>
	</div>
	
	
		<h2>justify-content: space-around</h2>
	<div class="container" style="justify-content:  space-around;">
		<div class="item">아이템1</div>
		<div class="item">아이템2</div>
		<div class="item">아이템3</div>
		<div class="item">아이템4</div>
	</div>
	
		<h2>justify-content: space-evenly</h2>
	<div class="container" style="justify-content:  space-evenly;">
		<div class="item">아이템1</div>
		<div class="item">아이템2</div>
		<div class="item">아이템3</div>
		<div class="item">아이템4</div>
	</div>
	
</body>
</html>

'CSS' 카테고리의 다른 글

[CSS] FlexItem의 세밀한 제어 flex 속성  (0) 2024.07.04
[CSS] 교차축 정렬에는 align-items와 align-content 이다.  (0) 2024.07.04
[CSS] flex-wrap 이해하기  (0) 2024.07.04
css 공부  (0) 2024.07.02
[CSS] flex-direction 속성이란?  (0) 2024.07.01
'CSS' 카테고리의 다른 글
  • [CSS] FlexItem의 세밀한 제어 flex 속성
  • [CSS] 교차축 정렬에는 align-items와 align-content 이다.
  • [CSS] flex-wrap 이해하기
  • css 공부
미로910
미로910
개발자를 꿈꾸는 민경이의 기록 블로그
  • 미로910
    개발 note
    미로910
  • 전체
    오늘
    어제
    • 분류 전체보기
      • 설치 메뉴얼
      • HTML
      • JAVA
        • Java 기초
        • Java 응용
        • 자료구조
        • HTTP
        • JSP 프로그래밍
      • MySQL
        • MySQL 기본
        • 1일 1쿼리
      • CSS
      • Spring boot
      • JS
        • 게시판 만들기
      • Git
      • Flutter
        • MVVM 활용
        • 심화 버전
        • 1일 1 Flutter
      • 디자인 패턴의 활용
      • error note
      • My Project
        • [졸작] LLM 기반 특허 유사도 분석 시스템
        • 도서 관리 프로그램 (final project)
        • amigo
        • 친구 매칭 프로그램(FMP)
      • Python
      • 딥러닝
      • 네트워크
      • 공부 노트
        • 연구회
        • 자료구조
      • 기타
  • 블로그 메뉴

    • 홈
    • 전체보기
    • -----------------------
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Flutter
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
미로910
[CSS] 주축 방향 정렬 justify-content 란?
상단으로

티스토리툴바