๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŒŒ | WEB DEV/HTML CSS

CSS ํฌ์ง€์…˜ (1)_๋ถ€๋ชจ์š”์†Œ ์ž์‹์š”์†Œ

by KASSID 2022. 1. 5.

๋ชฉ์ฐจ

    728x90

    position ์†์„ฑ

    : static, fixed, relative, absolute

     

    ๊ทธ ์ค‘์—์„œ ์ด๋ฒˆ์— ๋‹ค๋ฃฐ ๋‚ด์šฉ์€ ์•„๋ž˜์˜ ๋‘๊ฐ€์ง€์ด๋‹ค.

     

    relative -> ๋ถ€๋ชจ์š”์†Œ์—!

    absolute -> ์ž์‹์š”์†Œ์—!

     

    ์˜ˆ์‹œ

    <div class="parent">
            <div class="child"></div>
    </div>

     

    .parent {
        background-color: blueviolet;
        width: 600px;
        height: 400px;
        position: relative;
    }
    .child {
        background-color: rgb(140, 132, 190);
        width: 200px;
        height: 100px;
        position: absolute;
    }

    position์†์„ฑ์„ ๋ถ€๋ชจ์š”์†Œ์— relative, ์ž์‹์š”์†Œ์— absolute๋กœ ์ง€์ •ํ•ด์ฃผ์—ˆ๋‹ค.

     

    ์ด๋ ‡๊ฒŒ๋งŒ ํ•ด๋†“์œผ๋ฉด ์•„๋ฌด ๋ณ€ํ™”๊ฐ€ ์—†๋‹ค.

    ์ขŒํ‘œ๋ฅผ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค!

     

    ์ขŒํ‘œ๊ฐ’์€ top, bottom, left, right์œผ๋กœ ๋ถ€์—ฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๊ณ 

    ๊ฐ๊ฐ ์ƒํ•˜์ขŒ์šฐ์˜ ๊ฐ€์žฅ ๋๋ถ€๋ถ„์ด 0์ด๋‹ค.

    ๋˜ํ•œ, position์†์„ฑ๊ณผ ํ•จ๊ป˜ํ•˜์ง€ ์•Š์œผ๋ฉด ์˜๋ฏธ๊ฐ€ ์—†๋‹ค!

    .parent {
        background-color: blueviolet;
        width: 600px;
        height: 400px;
        position: relative;
    }
    .child {
        background-color: rgb(140, 132, 190);
        width: 200px;
        height: 100px;
        position: absolute;
        /*↓ position๊ณผ ํ•จ๊ป˜ ์“ฐ์ง€ ์•Š์œผ๋ฉด ์˜๋ฏธ X*/
        right: 0;
        bottom: 0;
    }

    right 0, bottom 0์œผ๋กœ ์˜ค๋ฅธ์ชฝ ๊ฐ€์žฅ ์•„๋ž˜๋กœ ์œ„์น˜ํ•˜๊ฒŒ ํ•˜์˜€๋‹ค.


    ์ด๋ฒˆ์—๋Š” relative์™€ absolute๋ฅผ ๊ฐ๊ฐ์˜ ์š”์†Œ์— ๋„ฃ์–ด์ฃผ๋Š” ์ด์œ ๋ฅผ ํ•œ ๋ฒˆ ์•Œ์•„๋ณด์ž!

     

    ๋ถ€๋ชจ์š”์†Œ์— ์ ์šฉํ–ˆ๋˜ relative๋ฅผ ์ง€์›Œ๋ณด๋ฉด

    ์ด๋ ‡๊ฒŒ ์ž์‹์š”์†Œ๊ฐ€ ์ฐฝ์˜ ๊ฐ€์žฅ ์•„๋ž˜์— ๋ฐฐ์น˜๊ฐ€ ๋œ๋‹ค.

    ๊ธฐ์กด์˜ ๋ถ€๋ชจ์ธ div๊ฐ€ ์•„๋‹Œ body๋ฅผ ๋ถ€๋ชจ๋กœ ์ธ์ง€๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค!

     

    ์ฆ‰, relative์™€ absolute๋กœ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ๋งบ์–ด ์ฃผ์–ด์•ผ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

     

     

    ๋Œ“๊ธ€