Grid 레이아웃은 단순히 행과 열을 나누는 것에서 끝나지 않는다.
Grid 컨테이너 안에서 아이템을 어디에, 어떻게 정렬할 것인지도 제어할 수 있다.
이번 챕터에서는
- Grid 내부에서 1개 박스 배치
- 여러 박스의 정렬 방식
justify-content,align-items의 역할
을 예제로 정리한다.
📌 핵심 개념 먼저 정리
Grid에서 내부 배치는 부모(Grid Container) 기준으로 결정된다.
속성 | 역할 |
justify-content | 가로(main axis) 방향 정렬 |
align-items | 세로(cross axis) 방향 정렬 |
중요:Grid에서 “아이템을 움직이고 싶으면”👉 아이템이 아니라 부모(Grid 컨테이너)를 조절한다
🧱 예제 1 – 박스 1개 배치
목표
큰 박스의 오른쪽 아래에 작은 박스를 배치

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
.outer {
display: grid;
/* main axis */
justify-content: end;
/* cross axis */
align-items: end;
width: 500px;
height: 500px;
border: 2px solid skyblue;
background-color: aliceblue;
}
.inner {
border: 1px solid red;
background-color: pink;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<!-- inner를 움직이기 위해선 outer를 조절해야한다
그렇기에 inner가 두개가 존재할 때 각각 움직이기 위해선
각 inner에 맞춰 outer가 두개 존재해야만 한다 -->
<div class="outer">
<div class="inner">안녕</div>
</div>
</body>
</html>
결과 해석
.inner는 Grid Item
.outer가 Grid Container
justify-content: end→ 오른쪽
align-items: end→ 아래쪽
👉 아이템을 움직이는 게 아니라, 배치 기준을 바꾼다
🧠 왜 inner에 정렬을 주지 않을까?
inner는 "배치 대상"
outer는 "배치 규칙을 가진 공간"
- inner는 움직일 수 없음
- outer가 아이템을 어디에 놓을지 결정
👉 이 개념이 안 잡히면 Grid/Flex가 계속 헷갈린다
🧱 예제 2 – 박스 여러 개 배치 (space-between)
목표
3개의 박스를 좌우로 균등 분배

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
.outer {
display: grid;
grid-template-columns: auto auto auto;
justify-content: space-between;
width: 500px;
border: 2px solid skyblue;
background-color: aliceblue;
}
.inner {
border: 1px solid red;
background-color: pink;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner">안녕</div>
<div class="inner">안녕</div>
<div class="inner">안녕</div>
</div>
</body>
</html>
결과 해석
- Grid 칸은 3개
- 아이템 사이 공간을 자동 분배
- 첫 번째는 왼쪽 끝, 마지막은 오른쪽 끝
👉 Flex의
space-between과 동작 개념은 동일📐 Grid에서 정렬 기준 다시 정리
Grid의 정렬 축은 항상 컨테이너 기준이다.
justify-content → 가로 방향
align-items → 세로 방향
값 | 의미 |
start | 시작 지점 |
center | 가운데 |
end | 끝 |
space-between | 사이 균등 |
space-around | 양쪽 여백 포함 |
space-evenly | 완전 균등 |
🧩 예제 3 – 영역별로 다른 정렬 적용
구조
- 위 영역: 오른쪽 정렬
- 아래 영역: 가운데 + 아래 정렬

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
.outer {
width: 500px;
border: 2px solid skyblue;
background-color: aliceblue;
}
.inner {
border: 1px solid red;
background-color: pink;
width: 100px;
height: 100px;
}
.box1 {
height: 250px;
display: grid;
justify-content: end;
}
.box2 {
height: 250px;
display: grid;
justify-content: center;
align-items: end;
}
</style>
</head>
<body>
<div class="outer">
<div class="box1">
<div class="inner"></div>
</div>
<div class="box2">
<div class="inner"></div>
</div>
</div>
</body>
</html>
핵심 포인트
- inner를 각각 움직이기 위해
- box1, box2 각각 Grid 컨테이너로 만든다
👉 inner가 여러 개면 outer도 여러 개가 필요
🧠 자주 쓰는 패턴
카드 안 버튼 우측 하단 고정
.card {
display: grid;
justify-content: end;
align-items: end;
}
모달 중앙 정렬
.modal {
display: grid;
place-items: center;
}
/* place-items = justify-items + align-items */
🔥 Grid 내부 배치 핵심 요약
- Grid에서 정렬은 부모가 한다
- 아이템은 가만히 있고, 공간이 배치한다
- 여러 아이템을 다르게 움직이고 싶으면
👉 Grid 컨테이너를 쪼갠다
✨ 한 줄 요약
Grid 내부 배치는 “아이템을 움직이는 기술”이 아니라 “공간을 설계하는 기술”이다
Share article