็ก์
CSS์ Position ์์ฑ ๋ณธ๋ฌธ
๐ข Position ์์ฑ
์์๊ฐ ๋ฌธ์ ์์์ ์ด๋ป๊ฒ ์์นํ ์ง๋ฅผ ์ ์.
๐น position ์ข ๋ฅ์ ํน์ง
| ์์ฑ๊ฐ | ์ค๋ช | top/right/bottom/left ์ฌ์ฉ | ๋ฌธ์ ํ๋ฆ ์ํฅ | ํ์ฉ ์์ |
| static | ์ผ๋ฐ ๋ฌธ์ ํ๋ฆ๋๋ก ๋ฐฐ์น (๊ธฐ๋ณธ๊ฐ) | โ ๋ฌด์๋จ | ์ผ๋ฐ | ๋๋ถ๋ถ ์ด๊ธฐ ์ํ |
| relative | ์๋ ์๋ฆฌ ๊ธฐ์ค์ผ๋ก ์ด๋ ๊ฐ๋ฅ | โ ์๋ ์ด๋ | โ ์๋ฆฌ ์ฐจ์ง ์ ์ง | tooltip ๊ธฐ์ค, ๋ฏธ์ธ ์์น ์กฐ์ |
| absolute | ๊ฐ์ฅ ๊ฐ๊น์ด ์์น ์ง์ ๋ถ๋ชจ ๊ธฐ์ค ๋ฐฐ์น | โ ์์น ์ง์ | โ ๋ถ๋ชจ ๊ธฐ์ค์ผ๋ก ๋ ๋ฆฝ | dropdown, modal, ์นด๋ ๋ฐฐ์น |
| fixed | ๋ทฐํฌํธ ๊ธฐ์ค ๋ ๋ฆฝ ๋ฐฐ์น, ์คํฌ๋กค ์ํฅ ์์ | โ ์์น ์ง์ | โ ๋ ๋ฆฝ | sticky header, ์คํฌ๋กค ๋ฒํผ |
| sticky | ์คํฌ๋กค ์ ๊ธฐ์ค ์์น๊น์ง ๋ฐ๋ผ๊ฐ๋ค ๊ณ ์ | โ top ๋ฑ ํ์ | โ ๋ถ๋ชจ ๋ด์์ | ํค๋ ๊ณ ์ , ํ ์ด๋ธ ํค๋ |
๐น position ํ์ฉ ๊ตฌ์กฐ
1๏ธโฃ ๋ถ๋ชจ-์์ ๊ด๊ณ ์ค์
<div class="parent">
<div class="child"></div>
</div>
- ๋ถ๋ชจ: position: relative → ๊ธฐ์ค์ .
- ์์: position: absolute → ๋ถ๋ชจ ๊ธฐ์ค ์์ ๋ฐฐ์น.
2๏ธโฃ ๋ถ๋ชจ ์์์ position: relative ์ค์
#parent {
position: relative;
width: 400px;
height: 300px;
background: #d0e6ff;
}
3๏ธโฃ ์์ ์์์ position: absolute ์ค์
#child {
position: absolute;
}
4๏ธโฃ ์์ ์์์ ์ขํ๋ฅผ ์กฐ์
#child {
position: absolute;
top: 20px; /* ๋ถ๋ชจ ์๋จ์์ 20px */
right: 30px; /* ๋ถ๋ชจ ์ค๋ฅธ์ชฝ์์ 30px */
width: 100px;
height: 50px;
transform: translate(-50%, -50%);
background: #ffb347;
}
- top/right/bottom/left ์์น ์กฐ์ .
- ์ค์ ์ ๋ ฌ: transform ํจ๊ป ์ฌ์ฉ.
๐ ์ด์ ์ํ๋ ํฌ์ง์ ์ ์์ ๋กญ๊ฒ ๋ฐฐ์นํ ์ ์๋ค.
โ ์ค๋ฌด ๊ฟํ โ
๋ถ๋ชจ๊ฐ <body> → relative ์๋ต ๊ฐ๋ฅ
absolute + z-index → ๊ฒน์น๋ ์์ ์์ ์ ์ด
sticky → ํน์ ์คํฌ๋กค ์์น์์ ๊ณ ์
fixed → ๋ทฐํฌํธ ๊ธฐ์ค ๊ณ ์ , ์คํฌ๋กค๊ณผ ๋ฌด๊ด
relative + absolute ์กฐํฉ → tooltip, modal, popup ๊ตฌํ
๐ธ z-index
๊ฐ์ ์์ ๋งฅ๋ฝ(stacking context) ์์์์ ๋ ์ด์ด ์์๋ฅผ ์ ํ๋ ๊ฐ
1๏ธโฃ position ์ค์ (ํ์)
.box {
position: relative; /* ๋๋ absolute, fixed, sticky */
}
- z-index๋ position์ด ์ค์ ๋ ์์์์๋ง ๋์
- position: static (๊ธฐ๋ณธ๊ฐ)์์๋ ๊ฑฐ์ ์๋ฏธ ์์
2๏ธโฃ z-index ๊ฐ ์ง์
.box1 {
position: relative;
z-index: 1;
}
.box2 {
position: absolute;
z-index: 10;
}
/* box2๊ฐ box1 ์์ ํ์ */
- ๊ฐ์ด ํด์๋ก ์(์)์ ๋ณด์
- ๊ฐ์ด ์์์๋ก ์๋(๋ค)์ ๊น๋ฆผ
- ์์ → ์๋ก ์ฌ๋ผ๊ฐ
- 0 → ๊ธฐ๋ณธ ๋ ๋ฒจ
- ์์ → ๋ค๋ก ๊ฐ
- ๊ฒน์น๋ ์์๋ผ๋ฆฌ๋ง ์๋ฏธ ์์
๐ฅ๏ธโ Self trainingโ ๐ฅ๏ธโ

CSS display: inline-block
https://www.w3schools.com/css/css_inline-block.asp
CSS Box Model
https://www.w3schools.com/css/css_boxmodel.asp
CSS Borders
https://www.w3schools.com/css/css_border.asp
CSS Margins
https://www.w3schools.com/css/css_margin.asp
CSS Padding
https://www.w3schools.com/css/css_padding.asp
CSS The display Property
https://www.w3schools.com/css/css_display.asp
CSS Float
https://www.w3schools.com/css/css_float.asp
'<style>' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| gradients ํจ์ (0) | 2026.03.20 |
|---|---|
| background ์์ฑ (0) | 2026.03.20 |
| float ์์ฑ (0) | 2026.03.19 |
| display ์์ฑ (0) | 2026.03.19 |
| Box Model์ padding ์์ฑ (0) | 2026.03.18 |