[CSS] Position

김현주·2021년 11월 25일
0

CSS

목록 보기
6/18
post-thumbnail

Position

position속성은 태그를 어떻게 배치시킬지를 지정한다. top, right, bottom, left 속성이 요소을 같이 사용한다.
position을 쓸 때 어떤 type으로 쓸지, 기준점을 어디로 잡을지 생각하고 써야한다.

① static: 기본값

② relative: 원래있던위치(자기자신의현재위치)를 기준으로 좌표를 지정한다.

③ absolute: position이 static이 아닌 요소를 기준으로 위치시킨다.

.wrap {
      width: 500px;
      height: 500px;
      background-color: wheat;
      margin: 0 auto;
      position: relative;
    }
img {
      width: 300px;
      height: auto;
      border-radius: 50%;
      position: absolute;
      left: 50px;
      top: 100px;
    }

④ fixed: viewport를 기준으로(스크롤에 영향을 받지 않고) 고정된 위치를 가진다.

👩‍💻참고1) viewport란? 브라우저창의 전체 크기
👩‍💻참고2) position을 absolute나 fixed로 설정시 block태그의 특징 중 하나인이 가로크기가 100%가 되는 것이 사라지게 된다. (float와 비슷)

⑤ sticky

profile
✨프론트엔드 개발자가 되기 위한 독학러✨

0개의 댓글