프론트엔드/CSS
CSS 32 z-index 속성
스펀지연구소
2021. 4. 4. 10:49
z-index
- 한 요소 위에 다른 요소를 쌓을 때 사용
- z-index 속성값이 작을수록 아래에 쌓임
<!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>
<style>
#box1{position: absolute;top: 0px; left: 0px;width: 100px; height: 100px;background: blue;
z-index: 3;} /*z-index를 3으로 설정하였습니다.*/
#box2{position: absolute;top: 30px; left: 30px;width: 100px; height: 100px;background: yellow;
z-index: 2;} /*z-index를 2으로 설정하였습니다.*/
#box3{position: absolute;top: 60px; left: 60px;width: 100px; height: 100px;background: green;
z-index: 1;} /*z-index를 1으로 설정하였습니다.*/
</style>
</head>
<body>
<div id="box1">box #1</div>
<div id="box2">box #2</div>
<div id="box3">box #3</div>
</body>
</html>