티스토리 뷰

CSS

[CSS]position absolute - position relative

이채야채 2022. 1. 15. 12:16

position absolute는 가장가까운 relative 를 가진 부모 기준으로 움직인다.

 

.nav__notification {
  background-color: tomato;
  width: 30px;
  height: 30px;
  border-radius: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-weight: 600;
  position: absolute;
  right: 5px;
}

위의 문제점?

position absolute가 적용이 body에 되버려서 body기준으로 right 5px인것

 

position relative를 그럼 그위의 부모에다가 적용을 또시켜야됨

=> 적용시키니 위치가 변경됨

 

.nav__link {
  position: relative;
  color: black;
}

.nav__notification {
  background-color: tomato;
  width: 30px;
  height: 30px;
  border-radius: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-weight: 600;
  position: absolute;
  left: 15px;
  bottom: 15px;
}

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/10   »
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 31
글 보관함