z-index

2021. 7. 16. 10:54hello world!/css

    요소의 쌓임 순서(stack order)를 정의할 수 있다.

    정수 값을 지정하여 *쌓임맥락 (stacking context)에서의 레벨(순서)을 정의하는 방식으로 적용되며

    *위치 지정 요소에 대해 적용할 수 있는 속성이다.=포지션이 지정된 요소에만 적용 가능하다.

     

     

    * 위치 지정요소 positioned element

    position속성이 정의되어있는 요소를 말한다.

     

     

    * 쌓임맥락 

    동일한 위치에 요소들이 배치되면 요소들은 z축에서(겹쳐서) 쌓이게 된다.

    나중에 생성된 요소가 위에 배치된다.

     

     

    z-index의 기본값은 auto로써 이것은 새로운 쌓임맥락이 형성되지 않은 자연스러운 상태며

    z-index로 정수값을 지정해주면 숫자가 높은 순서대로 위쪽에 배치되게 된다.

     

     

     

     

    ▼ z-index 적용 전 

     


            
    <title>z-index</title>

            <style>
                divwidth100pxheight100pxpositionrelative;}
                div:nth-child(1) {background-coloryellow;}
                div:nth-child(2) {background-colorvioletbottom50px;}
                div:nth-child(3) {background-colorturquoisebottom100px;}
                div:nth-child(4) {background-color:tomatobottom:150px;}
            </style>
        </head>
        <body>
            <div class="first">1</div>
            <div class="second">2</div>
            <div class="third">3</div>
            <div class="fourth">4</div>
        </body>

     

    position: relative : 일반적 문서의 흐름에 따라 배치되는데, 상 하 좌 우 값에 따라 오프셋 적용

     

     

     

    ▼ z-index 적용 후

     


            
    <style>

                divwidth100pxheight100pxpositionrelative;}
                div:nth-child(1) {background-coloryellow;}
                div:nth-child(2) {background-colorvioletbottom50px;}
                div:nth-child(3) {background-colorturquoisebottom100px;}
                div:nth-child(4) {background-color:tomatobottom:150px;}
                .first { z-index4 ;}
                .second { z-index3 ;}
                .third { z-index2 }
                .fourth { z-index1 ;}
            </style>
        </head>
        <body>
            <div class="first">1</div>
            <div class="second">2</div>
            <div class="third">3</div>
            <div class="fourth">4</div>

     

    z-index.html
    0.00MB

     

    'hello world! > css' 카테고리의 다른 글

    구글 웹폰트 사용  (0) 2022.02.09
    border-radius (모서리라운드)  (0) 2021.07.16
    공용키워드(상속여부)  (0) 2021.07.14
    상속  (0) 2021.07.14
    의사요소 ::  (0) 2021.07.14
    맨 위로