position

๋ฆฌ์ถฉ๋…•ยท2023๋…„ 7์›” 23์ผ
0

css ๋กœ๊ณ 


๐Ÿ“– position

์—˜๋ฆฌ๋จผํŠธ์˜ ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ์†์„ฑ

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

๐Ÿ“Œ ๋ฐฉํ–ฅ ํ”„๋กœํผํ‹ฐ : top, bottom, left, right

  • ์†์„ฑ๋ณ„ ์˜ˆ์‹œ ํ™”๋ฉด
<style>
    .back{
      width: 300px;
      height: 400px;
      background-color: salmon;
    }
    div{
      width: 200px;
      height: 100px;
      border: 1px solid;
      text-align: center;
      line-height: 100px;
      background-color: beige;
    }
    div:nth-of-type(2){
      background-color: palegreen;
      position: static
    }
    div:nth-of-type(3){
      background-color: palevioletred;
    }
  </style>
<div class="back">
  <div>static</div>
  <div>static</div>
  <div>static</div>
  </div>

static

<style>
    .back{
      width: 300px;
      height: 400px;
      background-color: salmon;
    }
    div{
      width: 200px;
      height: 100px;
      border: 1px solid;
      text-align: center;
      line-height: 100px;
      background-color: beige;
    }
    div:nth-of-type(2){
      background-color: palegreen;
      position: relative;
      top: 20px;
      left: 20px;
    }
    div:nth-of-type(3){
      background-color: palevioletred;
    }
  </style>
<div class="back">
  <div>static</div>
  <div>relative</div>
  <div>static</div>
  </div>

relative

1๋ฒˆ์˜ static ์˜ˆ์‹œํ™”๋ฉด๊ณผ ๋‹ค๋ฅด๊ฒŒ ๊ธฐ์กด ์ž์‹ ์˜ ์œ„์น˜๋กœ๋ถ€ํ„ฐ top, left๋กœ๋ถ€ํ„ฐ ๊ฐ๊ฐ 20px ๋–จ์–ด์ ธ ๋ฐฐ์น˜๋œ๋‹ค.


absolute

๋ถ€๋ชจ ์š”์†Œ ์ค‘ static ์ด์™ธ์˜ ์†์„ฑ์œผ๋กœ ์ง€์ •๋œ ์š”์†Œ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— body๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜๋œ๋‹ค.

<style>
    .back{
      width: 300px;
      height: 400px;
      background-color: salmon;
    }
    div{
      width: 200px;
      height: 100px;
      border: 1px solid;
      text-align: center;
      line-height: 100px;
      background-color: beige;
      position: relative;
    }
    div:nth-of-type(2){
      background-color: palegreen;
    }
    div:nth-of-type(3){
      background-color: palevioletred;
      position: absolute;
      bottom: 5px;
      right: 10px;
    }
  </style>
<div class="back">
  <div>static</div>
  <div>static</div>
  <div>absolute</div>
  </div>



๐Ÿ“Œ Position ์†์„ฑ ์ด์šฉํ•ด ๋ฐ”๋‘‘ํŒ ๋งŒ๋“ค๊ธฐ

<style>
    .back{
      width: 300px;
      height: 300px;
      border: 1px solid;
    }
    .item{
      background-color: black;
      width: 100px;
      height: 100px;
    }
    .pos_rel{
      position: relative;
    }
    .pos_abs{
      position: absolute;
    }
    .pos_abs_{
      position: absolute;
    }
    .top{
      top : 0;
    }
    .bottom{
      bottom: 0px;
    }
    .left{
      left: 0;
    }
    .right{
      right: 0;
    }
    .midd{
      top: 100px;
      left: 100px;
      right: 100px;
    }
  </style>
<div class="back pos_rel">
    <div class="item pos_abs top left"></div>
    <div class="item pos_abs"></div>
    <div class="item pos_abs top right"></div>
    <div class="item pos_abs"></div>
    <div class="item pos_abs bottom midd"></div>
    <div class="item pos_abs bottom left"></div>
    <div class="item pos_abs"></div>
    <div class="item pos_abs bottom right"></div>
  </div>


โœ”๏ธŽ ๋‹ค์Œ ํฌ์ŠคํŒ…์—์„  ๋ฐ”๋‘‘ํŒ์„ ๋ฐฐ๊ฒฝํ™”๋ฉด ์ „์ฒด์— ์ ์šฉํ•ด๋ณด์ž


Css ๋กœ๊ณ  ์ฐธ์กฐ
https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/CSS3_logo_and_wordmark.svg/1452px-CSS3_logo_and_wordmark.svg.png

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 23์ผ

์ข‹์€ ๊ธ€ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ