WEB/CSS_ concepts

Fixed Position

bay07 2024. 3. 7. 10:24

 

▶ Fixed Position

요소를 Normal Flow에서 제거한다
사람이 보는 화면영역(viewport)를 기준으로 이동한다
요소가 차지하는 공간이 없어진다 

 

본인의 집을 버리고, 어딘가에 박혀버리는 것

절대로 움직이지 않는다 

우리가 보는 화면 기준으로 움직이게 되고, 화면이 움직이더라도 그 위치를 벗어나지 않는다 

보통 웹툰에서 계속 떠 있는 리모콘 같은 거 

어떤 브라우저 화면의 특정 위치에 고정시키는 것 

 

 

상태 코드 위치
원래상태
position fixed 설정



위랑 똑같이 보이긴 하지만, 여기서는 fixed가 자기 위치를 버렸다




fixed 설정
top 0

Fix가 위로 올라가버림
fixed 설정
top 0
right 0



fixed가 오른쪽 위에 짱박혀버렸다.
스크롤을 내려도 fixed 위치는 그대로 있음
웹툰 같은데 보면 다음화 보기 
그런거 고정할 때 쓴다. 

 

 

더보기
<!DOCTYPE html>
<html>

<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>CSS Position</title>
  <style>
    * { 
      box-sizing: border-box;
    }

    body {
      height: 1500px;
    }

    .container {
      position: relative;
      height: 300px;
      width: 300px;
      border: 1px solid black;
    }

    .box {
      height: 100px;
      width: 100px;
      border: 1px solid black;
    }

    .static {
      /* position: static; */
      background-color: lightcoral;
    }

    .absolute {
      position: absolute;
      background-color: lightgreen;
      top: 100px;
      left: 100px;
    }

    .relative {
      position: relative;
      background-color: lightblue;
      top: 100px;
      left: 100px;
    }

    .fixed {
      position: fixed;
      background-color: gray;
      top: 0;
      right: 0;
    }


  </style>
</head>

<body>
  <div class="container">
    <div class="box static">Static</div>
    <div class="box absolute">Absolute</div>
    <div class="box relative">Relative</div>
    <div class="box fixed">Fixed</div>
  </div>
</body>

</html>

'WEB > CSS_ concepts' 카테고리의 다른 글

z-index  (0) 2024.03.07
sticky position  (0) 2024.03.07
Absolute position  (0) 2024.03.07
Relative position  (0) 2024.03.07
static position  (0) 2024.03.07