19강 z-index

yoonuooh·2023년 4월 12일
0

CSS

목록 보기
19/19
post-thumbnail

z-index

z-index

  • 요소의 쌓임 순서를 정의
    - 기본값은 auto, 정수값으로 정의
    - 정수값은 쌓임 맥락에서의 레벨을 의미
    - 값이 클수록 전면에 표시
    - z-index가 같으면 나중에 생성된 것이 전면에 쌓임

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>z-index</title>
    </head>
    <style>
        div {
            width: 100px; height: 100px; position: relative;
        }
        div:nth-child(1){ background-color: yellow; }
        div:nth-child(2){ background-color: cyan; bottom: 50px; }
        div:nth-child(3){ background-color: ivory; bottom: 100px; }
        div:nth-child(4){ background-color: mediumslateblue; bottom: 150px; }
        .first { z-index: 4; }
        .second { z-index: 2;}
        .third { z-index: 2;}
        .fourth { z-index: 1;}
    </style>
    <body>
        <div class="first">1</div>
        <div class="second">2</div>
        <div class="third">3</div>
        <div class="fourth">4</div>
    </body>
</html>

출처 : 유노코딩, 입문자를 위한 CSS 기초 강의

profile
ISTJ의 재미없는 velog

0개의 댓글