<position ์์ฑ์ ๊ฐ๋ค>
- static : ์น์ฌ์ดํธ์ ๊ธฐ๋ณธ ์์ฑ๊ฐ(default ๊ฐ) , top right bottom left ๋ฑ ์์น ์์ฑ์ ๋ฌด์๋จ.
- relative: HTML ํ๊ทธ๊ฐ ์๋ ์์น์์ left right top bottom๊ฐ์ ํตํด ์์ง์
- absolute: ๋ถ๋ชจ์์ญ์์ left right top bottom ์ ์ด์ฉํด ์ ๋๊ฐ ๊ธฐ์ค์ผ๋ก ์ฃผ์ด์ง ์์น๋ก ์์ง์
- * ๋จ! ์ฌ๊ธฐ์ ๋ถ๋ชจ๋?: ๋ถ๋ชจ ํ๊ทธ๊ฐ relative, absolute, fixed ์์ฑ ์ค ํ๋์ฌ์ผ ํจ. ๋ง์ฝ ๋ถ๋ชจํ๊ทธ๊ฐ ํด๋น ์์ฑ์ ๊ฐ์ง๊ณ ์์ง ์๋ค๋ฉด bodyํ๊ทธ ๊ธฐ์ค์ผ๋ก ์์ง์ ์๋ํ๋ฉด bodyํ๊ทธ๋ relative๋ฅผ ๊ธฐ๋ณธ ์์ฑ์ผ๋ก ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ด๋ค
- fixed : absolute์ ๋น์ทํ์ง๋ง ์คํฌ๋กค๋ก ๋ด๋ ค๋ ๊ทธ ์์น์ ๊ณ ์ , ๋ฌด์กฐ๊ฑด ๋ธ๋ผ์ฐ์ ์ฐฝ ๊ธฐ์ค์
- Sticky : relative์ ๋น์ทํ์ง๋ง ์คํฌ๋กค๋ก ๋ด๋ฆฌ๋ฉด fixed์ฒ๋ผ ๊ทธ ์์น์ ๊ณ ์
์ผ๋จ ๊ธฐ๋ณธ ์ฝ๋
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href = "5-1style.css" rel = "stylesheet" type = "text/css" />
</head>
<body>
<div class = "box red">
box1
</div>
<div class = "box yellow">
box2
</div>
<div class = "box blue">
box3
</div>
</body>
</html>
.box {
width : 100px;
height : 100px;
}
.red {
background-color : red;
}
.yellow {
background-color: yellow;
}
.blue {
background-color: rgb(79, 96, 255);
}
# yellow ๋ฐ์ค์ locate ํด๋์ค{ top : 30px; left : 30px; position : relative; }๋ฅผ ์ถ๊ฐํ์ ๋
# yellow ๋ฐ์ค์ ์ถ๊ฐ๋ locate ํด๋์ค์ position์ absolute๋ก ๋ฐ๊ฟจ์ ๋

# yellow ๋ฐ์ค์ ์ถ๊ฐ๋ locate ํด๋์ค์ position์ static๋ก ๋ฐ๊ฟจ์ ๋
- static์ top, left, right, bottom ๋ฑ์ ์์น ์์ฑ์ ๋ฌด์ํ ๊ทธ๋ฅ default ๊ฐ์ด๋ค.

# yellow ๋ฐ์ค์ ์ถ๊ฐ๋ locate ํด๋์ค์ position์ fixed๋ก ๋ฐ๊ฟจ์ ๋
- ์ด ์์ ์์๋ absolute์ ๋ณ ๋ฐ ๋ค๋ฅผ๊ฒ ์๋ค.

- ์คํฌ๋กค์ด ์๊ธธ ๋ ๊น์ง ๋ฐ์ค๋ฅผ ๋ ์ถ๊ฐํ์ ๋
ํ์์ ์ผํ๋ชฐ ์ฌ์ดํธ์ ๋ค์ด๊ฐ๋ณด๋ฉด ์คํฌ๋กค์ ๋ด๋ ค๋ ์ค์ค์ด ๋ฐ๋ผ์ค๋ ์ง์ฐฉ๊ด๊ณต๊ฐ์ ๊ด๊ณ ๋, ํต๋ฉ๋ด ๋ฑ๋ฑ์ด ์ด fixed๋ฅผ ์ ์ฉํ ์ฌ๋ก๋ค๋ก ๋ณผ ์ ์๊ฒ ๋ค.


์ฌ๊ธฐ์ position์ absolute๋ก ๋ฐ๊พธ๋ฉด ์คํฌ๋กค์ ๋ด๋ ค๋ ๋นจ๊ฐ๋ฐ์ค ์์ ๊ฒน์ณ์ ธ ์๋ณด์ด๊ฒ ๋จ์ ํ์ธํ ์ ์๋ค. (์ ๋ฐ๋ผ์ด)
# yellow ๋ฐ์ค์ ์ถ๊ฐ๋ locate ํด๋์ค์ position์ sticky๋ก ๋ฐ๊ฟจ์ ๋


<display : flex>
์๋ ๋ด๊ฐ ํ์ฅ์ค์ต ๋ ์ง์๋ถ์ด ๋์ถฉ ์จ๋์ ์ฝ๋ ๋๋ถ์ ์กด์ฌ๋ฅผ ์๊ฒ ๋๋๋ฐ, display๋ผ๊ณ ๋ ํ๊ต์์ ๋ฐฐ์ด ์ธ๋ผ์ธ ๋ธ๋ก ์ธ๋ผ์ธ๋ธ๋ก๋ฐ์ ๋ชฐ๋์ด์ ์ ๋ง ์ ์ธ๊ณ์๋ค. ๊ทธ ๋ ์ง์ง ์ฃฝ์ด๋ผ ๋ด์ ์ค์ต์ ํจ์ค, ๊ฐ์๋ก๋ง ๋ณด๊ธฐ๋ก
๊ฐ์ฌ๋์ด ์ถ์ฒํ์ flex ์ฐ์ต ์ฌ์ดํธ : https://flexboxfroggy.com/#ko
๋ด๊ฐ ์ ๋ง ์ ๋ง ๋์ ๋ง์ด ๋ฐ์ ํฌ์คํ : https://studiomeal.com/archives/197
ใด ์ด๊ฑฐ ์ง์ง ์ฌํด์ ๋ฌธํ(?)์ ๋ฐ์์ผํ ์ ๋๋ก ์ต๊ณ ... ์ ๋ฃ ๊ฐ์๋ ํ์๋๋ฐ ์ผ๋จ ์ด ํฌ์คํ ๋ง์ผ๋ก๋ ์ถฉ๋ถํ๋ฏ.
๊ทธ ๋ display ์์ฑ ์ค grid๋ ๊ฐ์ด ํฌ์คํ ํ์ ๊ฒ๋ ์ด์ฌํ ๋ดค์๋๋ฐ ์๋ ์กฐ๊ธ.. ๊ผผ๊ผผํ์ง ๋ชปํ ๋ํํ flex๊ฐ ์ข ๋ ์ค์ฉ์ ์ธ ๊ฒ ๊ฐ์์ ์ผ๋จ ํจ์คํ์๋ค. ๋๋๋๋ ์ ์ค๋ช ํด์ฃผ์ จ๋๋ฐ ๋์ค์ ๊ธฐํ๋๋ฉด grid๋ก ํ๋ฒ ์ฌ์ดํธ๋ฅผ ๋ง๋ค์ด ๋ณด๋ ๊ฒ๋ ๋์์ง ์๊ฒ ๋ค.
https://d2.naver.com/helloworld/8540176 << ์ฌ๊ธฐ๋ flex๋ฅผ ์ด์ฉํ ์ฌ๋ฌ ๋ ์ด์์์ ์๊ฐ์์ผ์ฃผ๋๋ฐ ๋์๋๋๋ฏ.
1๋ถ์ฝ๋ฉ๋ ๋๋ถ์ ๊ฐ๋ ์ ์ก์๋๋ฐ ์ฌ์ค ๊ฐ๋ฐ์ ๋๊ตฌ๋ก ์ด๊ฒ ์ ๊ฒ ์ ์ฉํด๋ณธ๊ฒ ์ ๋ง ๋ง์ ๋์์ด ๋์๋ ๊ธฐ์ต์ด ๋๋ค.
์ฝ๋ฉ์ ์ผ๋จ ํด๋ด์ผ ์ค๋ ฅ์ด ๋์ด๋๋ค๋๊ฒ ๋ง๋๋ฏ (๊ทผ๋ฐ ๊ท์ฐฎ๋ค.)
<๋ฌธ์ 1>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href = "5-1style.css" rel = "stylesheet" type = "text/css" />
</head>
<body>
<div class = "box box1">
box1
</div>
<div class = "box box3">
box3
</div>
<div class = "box box2">
box2
</div>
</body>
</html>
๋๋ ๋ฌธ์ 1๋ฒ์์๋ง box 2๊ฐ ๋ค์์์ด์ผ ๊ฒฐ๊ณผ๊ฐ ์ ๋๋ก ์ถ๋ ฅ๋๋๋ผ,,, ๋ต์ ์ฝ๋๋ณด๊ณ ๋ญ๊ฐ ๋ฌธ์ ์ธ์ง ๋ค ํ๊ณ ๋ด์ผ๊ฒ ๋ค.
html ์ฝ๋๋ ๋จ์ ๋ฌธ์ ์ค์๋ box3์ ์ ๋ฌด ์ฐจ์ด๋ง ์๋ ์ ๋๋ ์๋ตํ๊ฑฐ๋ ์ฐจ์ด๊ฐ ์๋๋ผ๋ <body>์ ๋ด์ฉ๋ง ์ ๋๋ก ํ๊ฒ ๋ค.
html, body {
padding : 0;
margin : 0;
}
.box {
display : inline-block;
position: relative;
margin : 0;
width : 100px;
height : 100px;
background-color: black;
color : #fff;
}
.box1 {
float : left;
}
.box2 {
margin-right : 10px;
float : right;
}
.box3 {
float : right;
}
<๋ฌธ์ 2>
html, body {
padding : 0;
margin : 0;
}
.box {
display : block;
position: relative;
margin : 0;
width : 100px;
height : 100px;
background-color: black;
color : #fff;
}
.box1 {
top : 0px;
left : 0px;
}
.box2 {
margin: 0 auto;
}
.box3 {
float:right;
}
<๋ฌธ์ 3>
<div class = "box box1">
box1
<div class = "box box2">
box2
</div>
</div>
.box {
position: relative;
color : #fff;
}
.box1 {
width : 200px;
height : 200px;
margin : 30px auto;
background-color: black;
}
.box2 {
width : 100px;
height : 100px;
margin : auto;
position : absolute;
transform: translateX(-50%) translateY(-50%);
left : 50%;
top : 50%;
background-color: #333;
vertical-align: middle;
}
<๋ฌธ์ 4>
<div class = "box box1">
box1
</div>
<div class = "box box2">
box2
</div>
html, body {
padding : 0;
margin : 0;
}
.box {
width : 100px;
height : 100px;
position: relative;
margin : 0;
color : #fff;
}
.box1 {
background-color: black;
}
.box2 {
position: absolute;
background-color: #333;
top : 50px;
left : 50px;
}
<๋ฌธ์ 5>
html, body {
padding : 0;
margin : 0;
}
.box {
position: absolute;
margin : 0;
color : #fff;
}
.box1 {
bottom : 0;
right : 0;
width : 400px;
height : 250px;
background-color: black;
}
.box2 {
width : 150px;
height : 150px;
position: absolute;
bottom : 0;
background-color: #333;
}
.box3 {
width : 150px;
height : 150px;
position: absolute;
margin : auto 0;
right : 0;
top : 0;
background-color: #333;
}
<div class = "box box1">
box1
<div class = "box box2">
box2
</div>
<div class = "box box3">
box3
</div>
</div>
----
์ ๋ต์ ๋ณด๊ณ ์๋๋ฐ ์ ๋ฒ ๊ตฌ๊ธ์ฌ์ดํธ๋๋ flex ๋จ๋ฐ์ ํ์ผ๋ฉด์ ์ด๋ฒ์ ์ ํ๋๋ ์์ผ์๊น.....
์ดํด... ๋ด์ผ ์ผ์ด๋์ ์๊ฐ๋จ์ผ๋ฉด ๋ค์ flex๋ก ์ฝ๋๋ฅผ ์ง๋ด์ผ๊ฒ ๋ค.
์ ๋ต ๋งํฌ : https://hackmd.io/@oW_dDxdsRoSpl0M64Tfg2g/rJ91twR1K
Css ์ฌํ: ํ๊ทธ๋ฅผ ๋ด๋ง๋๋ก ์์น์ํค๊ธฐ challenge ์ ๋ต - HackMD
# Css ์ฌํ: ํ๊ทธ๋ฅผ ๋ด๋ง๋๋ก ์์น์ํค๊ธฐ challenge ์ ๋ต ## ๋์ 1 ์ ๋ต  * HTML ```htm
hackmd.io