1. position
(1) ์ ์
์์๋ค์ด ํ๋ฉด์ ์ด๋ป๊ฒ ๋ฐฐ์น๋ ๊ฒ์ธ์ง ์ง์ ํ๋ ์์ฑ
์ด ์์ฑ์ ์์ ์์์๊ฒ ๋๋ฌผ๋ฆผ๋์ง ์๋๋ค.
(font-size: 2em ์ด ๋์ด์์ผ๋ฉด ์์ ์์๋ค์ ํฐํธ ํฌ๊ธฐ๋ ๋๋ฅผ ๊ฑฐ๋ญํ ์๋ก ๋ณต๋ฆฌ๋ก ์ปค์ก์๋ค.)
** top, bottom,left,right
: ๊ธฐ์ค์ ์์ ์ผ๋ง ๋งํผ ๋จ์ด์ก๋๊ฐ๋ฅผ ๋ํ๋ธ๋ค.
(top = 25px ๊ธฐ์ค ์ ์์ 25px ๋งํผ ๋ด๋ ค๊ฐ๋ค. bottom = 30px ๊ธฐ์ค ์ ์์ 30px ์ฌ๋ผ๊ฐ๋ค.
left = 80px ๊ธฐ์ค ์ ์์ 80px ๋งํผ ์ค๋ฅธ์ชฝ์ผ๋ก ๊ฐ๋ค. right = 40px ๊ธฐ์ค ์ ์์ 45px ๋งํผ ์ผ์ชฝ์ผ๋ก ๊ฐ๋ค. )
(2) ์์ฑ
ใฑ. static
๊ธฐ๋ณธ๊ฐ, ์ ์ ์ผ๋ก ํ์ด์ง ํ๋ฆ์ ๋ฐ๋ฅธ๋ค.
top, bottom, left,right,z-index ์จ๋ดค์ position: static;์ด๋ฉด ์ ์ฉ๋์ง ์๋๋ค.
ใด. relative
์๋ ์์๊ฐ ์๋ ์์น๋ฅผ ๊ธฐ์ค์ผ๋ก top,bottom,left,right ๊ฐ์ด ์ ์ฉ๋๋ค.
(top= 30px์ ๋ฃ์ผ๋ฉด ์๋ ์๋ ์์น๋ณด๋ค 30px ๋ฐ์ผ๋ก ๋ด๋ ค๊ฐ๊ฒ ๋ค๋ ์๋ฏธ์ด๋ค. left = 30px์ด๋ฉด 30px๋งํผ ์ค๋ฅธ์ชฝ์ผ๋ก ๊ฐ๋ค๋ ๋ง์ด๋ค. )
์์์ ์์น๋ ์ด๋ํด๋, ์์๊ฐ ์ฐจ์งํ๊ณ ์๋ ๊ณต๋ฐฑ์ ๊ทธ๋๋ก ์ ์ง๋๋ค.
(์ฌ๋์ด ์์์์ ์ผ์ด๋๋ ์์๋ ์๋ ์์น์ ๊ทธ๋๋ก ์๋๋ค. ๊ทธ๊ฒ์ ์๊ฐํ๋ฉด ๋๋ค.)
ใท. absolute
๋ถ๋ชจ ์์ ์ค ์ต์ด๋ก static์ด ์๋ ๋ ์์ ๊ธฐ์ค์ผ๋ก, top~right ์ด๋์ ํ๋ค.
(ex - top = 30px ํ๋ฉด ๋ถ๋ชจ ์์์ ๋งจ ์์์๋ถํฐ 30px ๋จ์ด์ง ๊ฒ์ด๋ค.
left = 30px ํ๋ฉด ๋ถ๋ชจ ์์์ ๋งจ ์ผ์ชฝ์์๋ถํฐ 30px ๋จ์ด์ง ๊ฒ์ด๋ค. )
ํด๋น ์์ฑ์ผ ๋, ์์๊ฐ ์์ง์ด๋ฉด, ์์๊ฐ ์ฐจ์งํ๋ ๊ณต๋ฐฑ์ ํ์ ์์๋ค์ด ์ฑ์ด๋ค.
ใน. fixed
๋ทฐํฌํธ๋ฅผ ๊ธฐ์ค์ผ๋ก top~right ์ด๋์ ํ๋ค.
(๋ทฐํฌํธ: ํ์ฌ ๋ณด๊ณ ์๋ ์ปดํจํฐ ํ๋ฉด)
์ปดํจํฐ ํ๋ฉด ์์ฒด๊ฐ ๊ธฐ์ค์ด ๋์ ์คํฌ๋กค์ ๋ด๋ ค๋ fixed๋ ๋ ์์ ์กฐ์ ๋ ์์น์ ๊ทธ๋๋ก ์๋ค.
ใ . sticky
์์๊ฐ ์ธ์ ๊น์ง ์คํฌ๋กค ๋ ์ ์๋์ง๋ฅผ ์ค์ ํ๋ ์์ฑ์ด๋ค.
position = sticky๋ก ๋์ด์๊ณ , top = 30px ์ด๋ฉด,
์ ์์ ์ผ๋ก ์คํฌ๋กค์ด ๋๋ค๊ฐ, viewport์ ์์์ ๊ฑฐ๋ฆฌ ์ฐจ์ด๊ฐ 30px ๋๋ฉด ๊ทธ ๋ค์๋ถํฐ ๋ ์ด์ ์คํฌ๋กค ๋์ง ์๊ณ
ํด๋น ์์๋ fixed ๋๋ค.
(์ธํฐ๋ท ๊ธฐ์ฌ ์ฝ์ ๋, ์ฒ์์ ํ๋จ์ ์๋ค๊ฐ ์คํฌ๋กค์ ํตํด
์ด๋ ์ ๋ ์๋จ์ ์กด์ฌํ๋ ์๊ฐ, ๊ณ ์ ๋๋ ์ ์์ ๊ด๊ณ ํ์ ์ฐฝ์ ์๊ฐํ๋ฉด ๋ ๊ฒ์ด๋ค.)
2. z-index
๋ถ๋ชจ ์์ ๊ฐ์๋ ์์์ด ํญ์ ์ฐ์ ์ ์ผ๋ก ์์ ๋์จ๋ค.
z-index๊ฐ ์ ์ฉ๋๋ ๊ฒ์ ํ์ ์์๋ผ๋ฆฌ ๋ง์ด๋ค.
๊ฒน์น ๋ ๋งจ ์๋ก ๊ฐ ์ฐ์ ์์๋ฅผ ์ ํ๋ ๊ฒ์ด๋ค.
z - index = auto; ๊ฐ ๊ธฐ๋ณธ๊ฐ์ธ๋ฐ auto = 0๊ณผ ๊ฐ๋ค.
๊ฒน์น๋ ์์ A์ z-index๊ฐ auto์ผ๋, ๊ฒน์น๋ ์์B๊ฐ 0๋ณด๋ค ํฌ๋ฉด ๋งจ ์์ ํ๊ธฐ๋๊ณ , 0๋ณด๋ค ์์ผ๋ฉด A๊ฐ ๊ฒน์น๋ ๋ถ๋ถ์ ํ๊ธฐ ๋๋ค.
3. ์ค์ค๋ก ํด๋ณด๊ธฐ
<!DOCTYPE html>
<html lang="ko">
<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>์ค์ต ํ์ด์ง </title>
<link rel="stylesheet" href="1_style.css">
</head>
<body>
<div class="outer">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div class="five">5
<div class="inner">
5-1
</div>
</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
</body>
</html>
/* */
.outer{
position: relative;
border: 5px dashed darkgreen;
background-color: darkred;
width: calc(100vw - 32px);
height: calc(100vw - 32px);
align-items: center;
}
body{
overflow: scroll;
}
.outer > div{
display: inline-block;
border: 2px solid navajowhite;
background-color: rgb(155, 155, 155);
width: calc((100vh - 32px) / 4);
height: calc((100vh - 32px) / 4);
margin: 20px;
padding: 0 0 0 0;
}
.outer > div.five{
display: block;
position: sticky;
top: 10px;
left: 10px;
margin: 0;
background-color: darkorange;
margin: 20px;
padding: 0 0 0 0;
}
.outer > div.five > div.inner{
position: absolute;
top: 10px;
display: inline - block;
background-color: aqua;
width: 40px;
height: 40px;
margin: 0px;
}