z-index๋ณต์กํ ์นํ์ด์ง๋ฅผ ๊ตฌํํ ๋ ๋ง์น 3์ฐจ์ ๊ณต๊ฐ์ฒ๋ผ ์์๋ฅผ ์๋ค๋ก ๊ฒน์ณ์ ๋ฐฐ์นํด์ผ ๊ฒฝ์ฐ๊ฐ ์๊ธฐ๋๋ฐ ์ด ๋ ์ด์ฉํ๋ ์์ฑ์ด๋ค.
z-index ์์ฑ์ ์ฌ์ฉํ๋ฉด ๊ธฐ๋ณธ์ ์ธ ๊ท์น์ ๋ฌด์ํ๊ณ HTML ๋ฌธ์ ์์์ ๋จผ์ ๋์จ ์์๋ฅผ ๋์ค์ ๋์จ ์์๋ณด๋ค ์์ผ๋ก ๋์ค๊ฒ ํ ์ ์๋ค.
โ๏ธz-index ์์ฑ์ ๋๋ฌด ๋ง์ด ์ฌ์ฉํ๋ฉด ์๋์ ๊น์ด๋ฅผ ํ์
ํ๊ธฐ ์ด๋ ค์์ง๋ฏ๋ก ์คํ์ผ ์ ์ง๋ณด์๊ฐ ํ๋ค์ด์ง ์ ์๋ค.
๐ก ์กฐ๊ฑด
position์ดstatic์ด ์๋ ๊ฐ์ผ ๋
flex-itmes์๋ ์ฌ์ฉ ๊ฐ๋ฅ (position์ด ์์ด๋)

โ๏ธ ๋ถ๋ชจ ์์ ์์์ ํ์ ์์๋ค๋ผ๋ฆฌ์ ์์๋ฅผ ์ง์ ํ ๋ ์ฌ์ฉ

โ๏ธ before
.circle.blue{
background-color: blue;
position: relative;
}
.circle.orange{
background-color: orange;
position: relative;
}
๋ ๋ค position: relative ์ด๋ฏ๋ก ๋ ๋ฐ์ ์ ํ ์ค๋ ์ง๊ฐ ํ๋์ ๋ฎ๋๋ค.
๊ทธ๋ ๋ค๋ฉด ํ๋์ ๋ ์๋ก ์ฌ๋ฆฌ๊ณ ์ถ๋ค๋ฉด ์ด๋ป๊ฒ ํด์ผํ ๊น?
์ด๋ด ๋ ์ฌ์ฉํ๋ ๊ฒ์ด z-index ์์ฑ์ด๋ค.

โ๏ธ after
.circle.blue{
background-color: blue;
position: relative;
z-index: 2;
}
.circle.orange{
background-color: orange;
position: relative;
}
z-index๊ฐ ๋์ ๊ฐ์ ๊ฐ์ง๋ ๊ฒ์ด ์๋ก ์จ๋ค.
๐ก
z-index๊ฐ ์์ ๋
position: static์ด ์๋ ์์ - ๋ฌด์กฐ๊ฑดposition์์ฑ์ดstatic์ธ ์์ ์๋ก ์ฌ๋ผ์จ๋ค.position: static์ธ ์์ ๋ผ๋ฆฌ - HTML ๋ฌธ์ ์์์ ๋์ค์ ๋์ค๋ ์์๊ฐ ๋จผ์ ๋์ค๋ ์์ ์๋ก ์ฌ๋ผ์จ๋ค.position: static์ด ์๋ ์์ ๋ผ๋ฆฌ - HTML ๋ฌธ์ ์์์ ๋์ค์ ๋์ค๋ ์์๊ฐ ๋จผ์ ๋์ค๋ ์์ ์๋ก ์ฌ๋ผ์จ๋ค.
๐ก
z-index๊ฐ ์์ ๋โ๏ธ
position์์ฑ์ดstatic์ด ์๋ ์์์ ๊น์ด๋ฅผ ์กฐ์ ํ ์ ์์
position: static์ธ ์์ -z-index: autoz-index > 0์์ -position: static์์๋ณด๋ค ์์ผ๋ก ์ฌ๋ผ์จ๋ค.z-index < 0์์ -position: static์์๋ณด๋ค ๋ค๋ก ๋ด๋ ค๊ฐ๋ค.position: static์ด ์๋ ์์ ๋ผ๋ฆฌ -z-index์์ฑ๊ฐ์ด ํด ์๋ก ์์ผ๋ก ์ฌ๋ผ์ค๊ณ , ์์ผ๋ฉด ์์์๋ก ๋ค๋ก ๋ด๋ ค๊ฐ๋๋ค. (์: z-index: 1์ธ ์์๋ณด๋ค z-index: 2์ธ ์์๊ฐ ๋ ์์ ๋์ค๊ณ z-index: -1์ธ ์์๋ณด๋ค z-index: -2์ธ ์์๊ฐ ๋ ๋ค๋ก ๋ค์ด๊ฐ)
z-index: -1๐ก ์คํํน ์ปจํ ์คํธ
z-index๊ฐ ์๋๋๋ ๊ธฐ์ค์

โ๏ธ ์คํํน ์ปจํ
์คํธ๊ฐ ์ง์ ์ด ์๋์ด์์ผ๋ฉด --> ์ต ์์ ์์ : HTML
โก๏ธ HTML์์์ ๊ผด์ฐ
== position:absolute ์ ์ปจํ
์ด๋ ๋ธ๋ก๊ณผ์ ๊ด๊ณ์ ๋น์ทํจ!
โ๏ธ๋ถ๋ชจ์๊ฒ ์คํํน ์ปจํ ์คํธ๊ฐ ์๋์ง ์๋์ง๊ฐ ์ค์!
โ ๋ฌด์กฐ๊ฑด ์ซ์๊ฐ ํฌ๋ค๊ณ ์ ์ฒด ํ์ด์ง์ ๊ฐ์ฅ ๋จผ์ ๋์ค๋ ๊ฒ์ด ์๋๋ค.
โญ๏ธ๋ถ๋ชจ์ ์คํํน ์ปจํ ์คํธ๊ฐ ์๋ ์ง๋ฅผ ํ์ ํ๊ณ ์ฐ๋ฌผ์์ ๊ฐ๊ตฌ๋ฆฌ์ธ์ง ๊ธ๋ก๋ฒ 1์์ธ์ง ํ์ ํ๊ธฐ
[___]๋ก ๊ฐ์ธ์ ธ์๋ ๊ฒ์ด ์คํํน ์ปจํ ์คํธ(div)์ด๋ค.

z-index: 9999๊ฐ z-index: 1๋ณด๋ค ์์ ์๋ค.z-index: 9999 - ๊ธ๋ก๋ฒ(root) 1์
z-indx:9999๋ผ๋ ์ ๋ z-index:0๋ผ๋ ์คํํน ์ปจํ
์คํธ ์์์๋ง ์งฑ์ด๋ค.z-indx:9999์ ๋ถ๋ชจ์ธ z-index:0๋ ๋ถ๋ชจ์ ํ์ ์์์ธ z-index: 1๋ณด๋ค ์์ ์ซ์์ด๋ฏ๋ก z-index: 9999๊ฐ z-index: 1๋ณด๋ค ์๋์ ์๋ค.z-index: 9999 - ๋๋ค(z-index:0) 1์z-index: 9999 - ๊ธ๋ก๋ฒ(root)์์๋ z-index:1์๊ฒ ๋ฐ๋ฆฐ๋ค.๋ถ๋ชจ ์์์ z-index:0 (auto๊ฐ ์๋ ๊ฐ)์ ์ํด ์์ ์์๋ฅผ ์ง์ญ์ ์ผ๋ก ๋ง๋ ๋ค.