1.  position ์†์„ฑ

 

๐Ÿฅ‘  ๋ฐฐ์น˜ ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ
๐Ÿฅ‘  ๊ฐ ์š”์†Œ์˜ ์œ„์น˜๋ฅผ ์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

์ƒ๋Œ€ ์œ„์น˜ ์ขŒํ‘œ : ํƒœ๊ทธ ์š”์†Œ๋ฅผ ์ž…๋ ฅํ•œ ์ˆœ์„œ๋ฅผ ํ†ตํ•ด ์ƒ๋Œ€์ ์œผ๋กœ ์œ„์น˜๋ฅผ ์ง€์ •
์ ˆ๋Œ€ ์œ„์น˜ ์ขŒํ‘œ : ํƒœ๊ทธ ์š”์†Œ๋กœ ๋งŒ๋“ค์–ด์ง„ x์ขŒํ‘œ์™€ y์ขŒํ‘œ๋ฅผ ์„ค์ •ํ•ด ์ ˆ๋Œ€ ์œ„์น˜๋ฅผ ์ง€์ •

๐Ÿ’ก ํ•จ๊ป˜ ์ ์šฉ๊ฐ€๋Šฅํ•œ ์†์„ฑ
     top - y์ถ• ์ƒ๋‹จ๊ธฐ์ค€
     bottom - y์ถ• ํ•˜๋‹จ๊ธฐ์ค€
     left - x์ถ• ์ขŒ์ธก๊ธฐ์ค€
     right - x์ถ• ์šฐ์ธก๊ธฐ์ค€
     z-index - ์š”์†Œ์˜ ์Œ“์ž„ ์ˆœ์„œ๋ฅผ ์ •์˜. ๊ฐ’์ด ํด ์ˆ˜๋ก ์•ž์ชฝ์— ๋ฐฐ์น˜ ๋œ๋‹ค.

 

์ข…๋ฅ˜ ์„ค๋ช…
static ๋ฌธ์„œ์˜ ํ๋ฆ„(์œ„์—์„œ ์•„๋ž˜๋กœ ์ˆœ์„œ๋Œ€๋กœ ๋ฐฐ์น˜)์— ๋งž์ถฐ ๋ฐฐ์น˜. ๊ธฐ๋ณธ๊ฐ’.
relative ์ƒ๋Œ€ ์ขŒํ‘œ์™€ ํ•จ๊ป˜ ์œ„์น˜๋ฅผ ์ง€์ • (์ƒ๋Œ€์œ„์น˜ ์ง€์ •๋ฐฉ์‹)
ํƒœ๊ทธ๊ฐ€ ๋งŒ๋“ค์–ด์ง„ ์ˆœ์„œ๋Œ€๋กœ ๋‚˜์—ด
absolute ์ ˆ๋Œ€ ์œ„์น˜ ์ขŒํ‘œ๋ฅผ ์„ค์ •. ๋ถ€๋ชจ ๋ฐ•์Šค ๊ธฐ์ค€์œผ๋กœ ์ขŒํ‘œ๋ฅผ ์„ค์ •
๋‹จ, ๋ถ€๋ชจ ์š”์†Œ๊ฐ€ static์ผ ๊ฒฝ์šฐ ๋ถ€๋ชจ ์š”์†Œ๋กœ ์ธ์‹ํ•˜์ง€ ์•Š์Œ
fixed ๊ณ ์ •๋œ ์ƒํƒœ๋กœ ์œ„์น˜๊ฐ€ ์ง€์ •

 


 

 

static

์œ„์น˜์ง€์ •๋ถˆ๊ฐ€ ) top, left, right, bottom์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์Œ

 

<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 300px;
            height: 300px;
            border: 4px solid black;
            margin-left: 30px;
            font-size: 30px;
            line-height: 300px;
            text-align: center;
        }

    </style>
</head>
<body>
    <div>static-1</div>
    <div>static-2</div>
    <div>static-3</div>
</body>

 


 

 

<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 300px;
            height: 300px;
            border: 4px solid black;
            margin-left: 30px;
            font-size: 30px;
            line-height: 300px;
            text-align: center;

            /* position ์†์„ฑ์„ ์ง€์ •ํ•˜์ง€ ์•Š์€ ์ƒํƒœ : static */
            left: 100px; /* ์ขŒํ‘œ ์ธ์‹์ด ์•ˆ๋จ */
            top: 100px; /* ์ขŒํ‘œ ์ธ์‹์ด ์•ˆ๋จ */
        }
    </style>
</head>
<body>
    <div>static-1</div>
    <div>static-2</div>
    <div>static-3</div>
</body>

 


relative

์œ„์น˜์ง€์ •๊ฐ€๋Šฅ) ๋ถ€๋ชจ๋ฐ•์Šค์˜ ์—ญํ• ๋กœ ์ฃผ๋กœ ์‚ฌ์šฉ 
<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 300px;
            height: 300px;
            border: 4px solid black;
            margin-left: 30px;
            font-size: 30px;
            line-height: 300px;
            text-align: center;

            position : relative; /* ์ƒ๋Œ€์ขŒํ‘œ */
            top : 100px;
            left : 100px;
        }

    </style>
</head>
<body>
    <div>relative-1</div>
    <div>relative-2</div>
    <div>relative-3</div>
</body>

 


absolute

html ํ™”๋ฉด(x, y)์„ ๊ธฐ์ค€์œผ๋กœ ์œ„์น˜๊ฐ€ ์ง€์ •.
๋งŒ๋“ค์–ด์ง„ ์ˆœ์„œ๋Œ€๋กœ ์œ„์ชฝ์— ๋ฐฐ์น˜ (์œ„์น˜์ง€์ • ๊ฐ€๋Šฅ) top, left, right, bottom์˜ ์˜ํ–ฅ์„ ๋ฐ›์Œ.
๊ธฐ์ค€์ด ๋˜๋Š” ์œ„์น˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ถ€๋ชจ ์š”์†Œ๋‚˜ ์กฐ์ƒ ์š”์†Œ ์ค‘ position ์†์„ฑ์ด relative์ธ ์š”์†Œ
absolute๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๊ทธ ์š”์†Œ๋ฅผ ๊ฐ์‹ธ๋Š” <div>๋ฅผ ๋งŒ๋“ค๊ณ  position ์†์„ฑ์„ relative๋กœ ์ง€์ •ํ•ด ๋†“๊ณ  ์‚ฌ์šฉํ•ด์•ผ ํ•จ

 

<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .movie { /* ๋ถ€๋ชจ ์š”์†Œ */
            width: 700px;
            height: 500px;
            border: 2px solid gray;
            background-color: darkslateblue;

            position: relative; /* ์ƒ๋Œ€ ์ขŒํ‘œ */
        }

        /* ์ž์‹ ์š”์†Œ */
        /* ๋ฒ„ํŠผ */
        .movie div {
            width: 120px;
            height: 120px;
            border: none;
            border-radius: 120px;
            background-color: antiquewhite;
            text-align: center;
            line-height: 120px;
            font-size: 30px;

            position: absolute;
        }

        .prev {
            top: 50%; /* top์œผ๋กœ์˜ ์œ„์น˜ */
            left: 10px; /* left๋กœ์˜ ์œ„์น˜ */
            margin-top: -60px; /* ๋ฐ˜์ง€๋ฆ„ ๊ฐ’๋งŒํผ ๋นผ์ค˜์•ผ ์ค‘์•™ ์ •๋ ฌ์ด ๋จ */
        }

        .play {
            top: calc(50% - 60px);
            left: calc(50% - 60px);
        }

        .next {
            top: calc(50% - 60px);
            right: 10px;
        }

    </style>
</head>
<body>
    <!--๋ถ€๋ชจ ์š”์†Œ relative -->
    <div class="movie">
        <!--์ž์‹ ์š”์†Œ absollute -->
        <div class="prev">PREV</div>
        <div class="play">โ–ถ</div>
        <div class="next">NEXT</div>
    </div>

</body>

 


fixed

์Šคํฌ๋กค๊ณผ ์ƒ๊ด€์—†์ด htmlํ™”๋ฉด๊ธฐ์ค€ ์ขŒ์ธก์ƒ๋‹จ์„ ๊ธฐ์ค€์œผ๋กœ ์ขŒํ‘œ๊ณ ์ •
top,left, right, bottom์˜ ์˜ํ–ฅ์„ ๋ฐ›์Œ

 

<head>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            height: 3000px; /* ์Šคํฌ๋กค ๋ฐ”๋ฅผ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด ๋ฌธ์„œ์˜ ๋†’์ด๋ฅผ ์ž„์˜์˜ ํฌ๊ธฐ๋กœ ์ง€์ • */
        }

        div {
            width: 300px;
            height: 300px;
            border: 4px solid black;
            margin-left: 30px;
            font-size: 30px;
            line-height: 300px;
            text-align: center;
        }

        div:nth-of-type(1) { /* div ๋ฐ•์Šค ์ค‘์—์„œ ์ฒซ ๋ฒˆ์งธ ๋ฐ•์Šค */
            background-color: red;
            left: 100px; /* ์™ผ์ชฝ ์ขŒํ‘œ */
            top: 100px; /* ์ƒ๋‹จ ์ขŒํ‘œ */
            position: absolute;
        }

        div:nth-of-type(2) { /* div ๋ฐ•์Šค ์ค‘์—์„œ ๋‘ ๋ฒˆ์งธ ๋ฐ•์Šค */
            background-color: orangered;
            right: 100px; /* ์˜ค๋ฅธ์ชฝ ์ขŒํ‘œ */
            bottom: 100px; /* ํ•˜๋‹จ ์ขŒํ‘œ */
            position: fixed;
        }

    </style>
</head>
<body>
    <div>absolute</div>
    <div>fixed</div>
</body>

 

์Šคํฌ๋กค ๋ฐ‘์œผ๋กœ ๋‚ด๋ ธ์„ ๋•Œ

 


z-index

 

<head>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        div {
            width: 300px;
            height: 300px;
            margin-left: 30px;
            font-size: 30px;
            line-height: 300px;
            text-align: center;

            position: absolute; /* ์ ˆ๋Œ€ ์ขŒํ‘œ */
        }

        div:nth-of-type(1) { /* div ๋ฐ•์Šค ์ค‘์—์„œ ์ฒซ ๋ฒˆ์งธ ๋ฐ•์Šค */
            background-color: indianred;
            left: 100px; /* ์™ผ์ชฝ ์ขŒํ‘œ */
            top: 100px; /* ์ƒ๋‹จ ์ขŒํ‘œ */
            z-index: 5;
        }

        div:nth-of-type(2) { /* div ๋ฐ•์Šค ์ค‘์—์„œ ๋‘ ๋ฒˆ์งธ ๋ฐ•์Šค */
            background-color: lightgoldenrodyellow;
            left: 250px; /* ์™ผ์ชฝ ์ขŒํ‘œ */
            top: 250px; /* ์ƒ๋‹จ ์ขŒํ‘œ */
            z-index: 3; /* ์šฐ์„  ์ˆœ์œ„ ๋ณ€๊ฒฝ */
        }

        div:nth-of-type(3) { /* div ๋ฐ•์Šค ์ค‘์—์„œ ์„ธ ๋ฒˆ์งธ ๋ฐ•์Šค */
            background-color: teal;
            left: 400px; /* ์™ผ์ชฝ ์ขŒํ‘œ */
            top: 400px; /* ์ƒ๋‹จ ์ขŒํ‘œ */
        }

    </style>
</head>
<body>
    <div>box-1</div>
    <div>box-2</div>
    <div>box-3</div>
</body>

 

 

 

 

 

[ ๋‚ด์šฉ ์ฐธ๊ณ  : IT ํ•™์› ๊ฐ•์˜ ๋ฐ ์ฑ… 'Do it HTML+CSS+์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์›น ํ‘œ์ค€์˜ ์ •์„' ]

+ Recent posts