CSS - position 속성 _ static / relative / absolute / fixed

SeomIIIΒ·2021λ…„ 8μ›” 25일
0

FRONTEND

λͺ©λ‘ 보기
9/11

πŸ“Œ position

βœ… static : μœ„μΉ˜λ₯Ό μ§€μ •ν•˜μ§€ μ•Šμ„ λ•Œ μ‚¬μš©ν•œλ‹€. top, bottom, left, right λ₯Ό 섀정이 λΆˆκ°€ν•˜λ‹€.

βœ… relative : static의 μ›λž˜ μœ„μΉ˜λΆ€ν„° 계산

βœ… absolute : μ›λž˜ μœ„μΉ˜μ™€ 상관없이 μœ„μΉ˜ 지정 κ°€λŠ₯ (κ°€μž₯ κ°€κΉŒμš΄ μƒμœ„μš”μ†Œλ₯Ό κΈ°μ€€μœΌλ‘œ!)

βœ… fixed : μ›λž˜ μœ„μΉ˜μ™€ 상관 없이 μœ„μΉ˜ 지정 κ°€λŠ₯ (μƒμœ„ μš”μ†Œμ—λ„ 영ν–₯을 받지 μ•ŠμŒ.)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            #contain{ width:800px; margin:0 auto; border:1px solid gray;}
            #header{height:50px; background-color: gray;}
            #wrap{height:200px; 
            /* ν•΄μ€˜μ•Ό 밑에 μΉœκ΅¬λ“€μ΄ λ‚΄κ°€ μ›ν•˜λŠ” λ°©ν–₯으둜... */
            position:relative;}

            #content1{width:100px; height:100px;
            background-color: purple;
            border:2px dashed green;
            /* μ•ˆμͺ½μ— 이게 있으면 λ°”κΉ₯μͺ½μ—λŠ” 거의 무쑰건 relative,, */
            position: absolute;
            top:10px; left:10px;
            z-index:20;}

            #content2{ width:100px; height:100px;
            background-color: yellow;
            border:2px dashed green;
            position:absolute;
            top:50px; left:50px;
            z-index: 10;}
        </style>
    </head>

    <body>
        <div id="contain">
            <div id="header">HEADER</div>
            <div id="wrap">
                <div id="content1">content1</div>
                <div id="content2">content2</div>
            </div>
            <div id="footer">FOOTER</div>
        </div>
        
    </body>
</html>

profile
FE Programmer

0개의 λŒ“κΈ€