์๊ตฌ์ฌํญ (Flexbox ํ์ฉ)
- HTML ๊ตฌ์กฐ: section ํ๊ทธ ๋ด๋ถ์ div๋ก ๋ ์นด๋ ํญ๋ชฉ 6๊ฐ๋ฅผ ๋ฐฐ์นํฉ๋๋ค.
- CSS: Flexbox๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ด์์์ ๊ตฌ์ฑํฉ๋๋ค.
- ๊ธฐ๋ณธ ์คํ์ผ:
- ๋ชจ๋ ์นด๋์ ๋๋น๋ ๊ท ์ผํด์ผ ํฉ๋๋ค.
- ์นด๋ ์ฌ์ด์๋ ์ผ์ ํ ๊ฐ๊ฒฉ(gutter)์ด ์์ด์ผ ํฉ๋๋ค.
- ๋ฐ์ํ ์กฐ๊ฑด:
- ๋ฐ์คํฌํฑ (ํ๋ฉด ๋๋น 1024px ์ด์): ์นด๋๊ฐ 3์ด๋ก ๋ฐฐ์น๋์ด์ผ ํฉ๋๋ค.
- ํ๋ธ๋ฆฟ (ํ๋ฉด ๋๋น 600px ์ด์, 1023px ์ดํ): ์นด๋๊ฐ 2์ด๋ก ๋ฐฐ์น๋์ด์ผ ํฉ๋๋ค.
- ๋ชจ๋ฐ์ผ (ํ๋ฉด ๋๋น 599px ์ดํ): ์นด๋๊ฐ 1์ด๋ก ๋ฐฐ์น๋์ด์ผ ํฉ๋๋ค.
- ํํธ: flex-wrap, calc(), ๊ทธ๋ฆฌ๊ณ ๋ฏธ๋์ด ์ฟผ๋ฆฌ๋ฅผ ์ฌ์ฉํด ๋ณด์ธ์.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:root {
--gap : 1vw;
}
.card-list {
display: flex;
flex-wrap: wrap;
gap: var(--gap);
}
.card-list__item {
flex-grow: 1;
flex-shrink: 0;
aspect-ratio: 1/1;
border-radius: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
flex-basis: 100%;
}
@media screen and (min-width: 600px) {
.card-list__item {
flex-basis: calc((100% - var(--gap)) / 2);
}
}
@media screen and (min-width: 1024px) {
.card-list__item {
flex-basis: calc((100% / 3) - var(--gap));
}
}
</style>
</head>
<body>
<section class="card-list">
<div class="card-list__item"></div>
<div class="card-list__item"></div>
<div class="card-list__item"></div>
<div class="card-list__item"></div>
<div class="card-list__item"></div>
<div class="card-list__item"></div>
</section>
</body>
</html>