KDT 코딩온 개발 14기 수강일기

KDT 포스코X코딩온 웹 과정 14기 5~6일 : position, z-index

worldstroy 2024. 9. 10. 21:24

Position

1. static : 정적 위치 지정 방식(기본값)

2. relative:상대 위치 지정방식

3. absolute: 절대 위치 지정방 식 ->static이 아닌 조상이 기준

4. fixed : 고정 위치 지정방식 => 뷰포트(브라우저)를 기준으로 배치

 

요소 쌓임 순서

1. 어떤 요소가 사용자와 더 가깝게 있는지를 결정

2. 요소에 position 속성의 값이 있는 경우 위에 쌓임(기본값 static)

3. 2번 조건이 같은 경우, z-index 속성의 숫자값이 높을 수록 위에 쌓임.

4. 2~3번 조건까지 같은 경우, html의 다음 구조일 수록 위에 쌓임.

#. z-index : 요소의 쌓임 정도를 지정함(position이 static이 아닐때만 반영됨)

#. position 속성의 값으로 absolute, fixed가 지정된 요소는 display 속성이 bloxk 처리됨.

 

######실습문제1#####

 

코드를 리뷰하며 느낀점 :
 CSS를 작성할 때에도 공통으로 작성되는 부분을 따로 빼서 작성하자.
 동일한 부분을 여러번 반복하는 건 좋은 방식이 아님.
 class 명을 의미 없는 item으로 표기하는 것도 좋아보이지 않았다.

#####실습문제2#####

 

#####실습문제3#####

.container {
  width: 500px;
  height: 700px;
  padding: 0;
  margin: 0;
  border: 5px solid darkblue;
}
.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  position: absolute;
  margin: calc(100wh - 100px);
}
.circle3 {
  background-color: #cb80ab;
  top: 350px;
  left: 300px;
  z-index: 50;
}
.circle4 {
  background-color: #e6d9a2;
  top: 350px;
  left: 250px;
  z-index: 40;
}
.circle5 {
  background-color: #c0c043;
  top: 300px;
  left: 200px;
  z-index: 30;
}
.circle6 {
  background-color: #5a3270;
  top: 250px;
  left: 150px;
  z-index: 0;
}
.circle7 {
  background-color: #cfcacd;
  top: 250px;
  left: 100px;
  z-index: 0;
}

div .circle .circle1 {
  width: 20px;
  height: 20px;
  background-color: black;
  left: 30px;
  top: 10px;
}

div .circle .circle2 {
  width: 10px;
  height: 10px;
  background-color: white;
  border: 1px solid black;
  left: 30px;
  top: 10px;
}

 


#. 특별히 어렵지 않은 경우, 느낀점은 기록하지 않습니다.