• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    해결됨

left:calc(100% - 100px) 질문드립니다.

23.02.17 12:38 작성 조회수 433

0

.container {
  position: relative;
  width: 100%;
  height: 104px;
  /* height:104px 이유 : box-sizing:border-box 설정 때문
   */
  background: rebeccapurple;
  border: 2px solid red;
}
.item {
  width: 100px;
  height: 100px;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  animation-name: moveBox;
  animation-duration: 2s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  position: absolute;
}
.item span {
  color: white;
}
@keyframes moveBox {
  from {
    border-radius: 0;
    left: 0;
  }
  to {
    border-radius: 50%;
    left: calc(100% - 100px);
  }
}

item에 애니메이션 효과를 넣고 .container에서 범위에 벗어나지 않게 @keyframes moveBox에서 left:calc(100% - 100px)을 했는데 영상 설명에서 .item width 크기가 100px이라고 하셨는데 이해가 잘 되지 않아서 질문드립니다ㅠㅠ

답변 1

답변을 작성해보세요.

1

안녕하세요 종규님!

item의 크기는 위의 .item에 적어주신 것 처럼 100px 입니다.
그리고 from 에서 애니메이션이 시작됩니다.
border-radius가 0 / 위치는 왼쪽 0에서 시작하고,
애니메이션이 흘러가는 동안 border-radius는 50%로 바뀌고 위치가 왼쪽 cal(100% - 100px)이 됩니다.

종규님의 애니메이션에서의 left: cal(100% - 100px)은 크기가 아닌 위치를 뜻합니다.

감사합니다.😁