티스토리 뷰

css

[CSS] POSITION 학습

IT개발~ 2023. 1. 16. 21:09

position


  • position: absolute; -
    • 기준: 부모 (box의 경우 부모는 body다)
    • 특징: 태그의 부모가 기준이된다.

  • position: fixed;
    • 기준: 브라우저
    • 특징: 부모와 상관없기에

  • position: relative; -
    • 기준: 내 위치
    • 예시: 태그의 부모로서 relative를 선택해준다.

  • position: static;
    • 기준이 없어 좌표적용이 필요없다.
    • 특징: 기본적인 적용

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 

                # position: 기준을 잡아주는 css 
                - position: absolute;  -
                    - 기준: 부모 (box의 경우 부모는 body다)
                    - 특징: 태그의 부모가 기준이된다.
                - position: fixed;     
                    - 기준: 브라우저
                    - 특징: 부모와 상관없기에
                - position: relative;  -
                    - 기준: 내 위치
                    - 예시: 태그의 부모로서 relative를 선택해준다.
                - position: static;    
                    - 기준이 없어 좌표적용이 필요없다.
                    - 특징: 기본적인 적용

                2.media query 
                3.tranition / animation 
          
            -->
    <style>
      div {
        width: 100%;
        min-height: 100px;
        height: auto;
        border: 1px solid red;
        background-color: red;
      }

      /* relative를 주어 parent를 기준으로 잡는 행위 */
      .parent {
        position: relative;
      }

      .target {
        position: fixed;
        top: 50px;
        width: 50%;
        right: 0;
        border: 3px solid blue;
        background-color: blue;
      }

      /* .box {
        width: 100px;
        height: 100px;
        border: 4px solid red;

        top: 100px;
        left: 100px;

        position: absolute;
      } */
    </style>
  </head>
  <body>
    <div class="other">other</div>
    <div class="parent">
      parent
      <div class="target">target</div>
    </div>
    <div class="other">other</div>

    <!-- <div class="box"></div> -->
  </body>
</html>

'css' 카테고리의 다른 글

[CSS} SASS 학습  (0) 2023.01.24
[CSS] z-index를 활용한 모달창 연습  (0) 2023.01.16
[CSS] 가상 요소  (0) 2023.01.16
[CSS] 가상클래스  (0) 2023.01.15
[CSS] 선택자  (0) 2023.01.14
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
글 보관함