Flexbox๋ฅผ ํ์ฉํ์ฌ ์ผ๋ฐ์ ์ธ ์น ์ปดํฌ๋ํธ์ธ Media Object ํจํด์ ๊ตฌํํ๊ณ , ๋ณต์กํ ํญ๋ชฉ ์ ๋ ฌ์ ์ฐ์ตํฉ๋๋ค.
์๊ตฌ์ฌํญ
- HTML ๊ตฌ์กฐ: comment-item ๋ธ๋ก ๋ด๋ถ์ comment-item__avatar (์ด๋ฏธ์ง)์ comment-item__body (๋ณธ๋ฌธ) ๋ ๊ฐ์ง ์์๋ฅผ ๋ฐฐ์นํฉ๋๋ค.
- CSS (Flexbox):
- comment-item์ Flex ์ปจํ ์ด๋๊ฐ ๋ฉ๋๋ค.
- **comment-item__avatar**๋ ์ผ์ชฝ ์๋จ์ ๊ณ ์ ๋ ํฌ๊ธฐ(์: 60px * 60px)๋ก ์ ์ง๋์ด์ผ ํฉ๋๋ค.
- **comment-item__body**๋ ๋จ์ ๊ณต๊ฐ ์ ์ฒด๋ฅผ ์ฑ์ฐ๋ฉฐ(Flex-grow), ๋ด๋ถ์ ์ ๋ชฉ(title)๊ณผ ๋ด์ฉ(text)์ด ์์ง์ผ๋ก ๋ฐฐ์น๋์ด์ผ ํฉ๋๋ค.
- ๋ฐ์ํ ์กฐ๊ฑด:
- ๋ชจ๋ฐ์ผ (ํ๋ฉด ๋๋น 600px ์ดํ): ์๋ฐํ๋ ๋ณธ๋ฌธ ์์ ์ค์ ์ ๋ ฌ๋์ด์ผ ํ๊ณ , ๋ณธ๋ฌธ์ ์๋ฐํ ์๋ ์ ์ฒด ๋๋น๋ฅผ ์ฐจ์งํด์ผ ํฉ๋๋ค. (์์ง ๋ ์ด์์)
- ๋ฐ์คํฌํฑ (ํ๋ฉด ๋๋น 601px ์ด์): ์๋ฐํ๋ ๋ณธ๋ฌธ ์ผ์ชฝ์ ์ํ ์ ๋ ฌ๋์ด์ผ ํ๋ฉฐ, ์๋ฐํ์ ๋ณธ๋ฌธ ๋ด์ฉ์ ์์ง ์ถ์ **flex-start**๋ก ์ ๋ ฌ๋์ด์ผ ํฉ๋๋ค. (์ํ ๋ ์ด์์)
<!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>
.comment-item {
display: flex;
align-items: flex-start;
gap: 1rem;
padding: 1rem;
border-radius: 1rem;
background-color: #f5f5f5;
}
.comment-item__avatar {
flex-basis: 60px;
flex-shrink: 0;
aspect-ratio: 1/1;
}
.comment-item__avatar img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
}
.comment-item__body {
display: flex;
flex-direction: column;
flex: 1 1 auto;
}
@media screen and (max-width: 600px) {
.comment-item {
flex-direction: column;
align-items: center;
gap: 0.5rem
}
.comment-item__body {
text-align: center;
}
}
</style>
</head>
<body>
<div class="comment-item">
<div class="comment-item__avatar"><img class="img" src="https://picsum.photos/60" alt="์ฌ์ฉ์ ์ฌ์ง"></div>
<div class="comment-item__body">
<h3 class="name">์ฌ์ฉ์์ด๋ฆ</h3>
<p class="desc">์ฌ์ฉ์์ ๋ณด</p>
</div>
</div>
</body>
</html>'w. Gemini' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ::highlight ๊ฐ์ ์์์ ๋ฑ์ฅ! CSS Custom Highlight API๋ก ํ ์คํธ ๊ฐ์กฐ๋ฅผ ํ์ ํ๋ค (0) | 2025.12.03 |
|---|---|
| ์ฐ์ต ๋ฌธ์ 2: ์์ฐ์ค๋ฝ๊ฒ ๋จ์ด์ง๋ ๋ฐ์ํ ๋ ์ด์์ (0) | 2025.11.18 |
| ์ฐ์ต ๋ฌธ์ 1: ๊ธฐ๋ณธ ๋ฐ์ํ ์นด๋ ๋ ์ด์์ (0) | 2025.11.18 |
| 4xx ๋น์จ ์์น ๋ฐ ํธ๋ํฝ ๊ธ์ฆ ๋ถ์ (0) | 2025.11.06 |
| ์ฐ์ต ๋ฌธ์ 1: ๊ฐ๋จํ To-Do ๋ฆฌ์คํธ ๊ตฌํ (0) | 2025.11.05 |
