Home > front end >  How to get CSS arrow to maintain angle during transformation
How to get CSS arrow to maintain angle during transformation

Time:09-29

I am trying to make a CSS scroll down arrow but it keeps on curving, how can I make this go straight down?

Thanks!

.arrow {
    content: "";
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border-left: none;
    border-top: none;
    border-right: 1px #262626 solid;
    border-bottom: 1px #262626 solid;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-name: arrow;
    -webkit-transform: rotate(45deg);
}

@keyframes arrow {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(10px, 10px);
  }
}
<div class="arrow"></div>

CodePudding user response:

You can try transform: translateY(20px) rotate(45deg);

.arrow {
    content: "";
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border-left: none;
    border-top: none;
    border-right: 1px #262626 solid;
    border-bottom: 1px #262626 solid;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-name: arrow;
    -webkit-transform: rotate(45deg);
}

@keyframes arrow {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(20px) rotate(45deg);
  }
}
<div class="arrow"></div>

CodePudding user response:

You're miss to add transform:rotate(45deg) on animation arrow that's why it its rotated. Try this

.arrow {
    content: "";
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border-left: none;
    border-top: none;
    border-right: 1px #262626 solid;
    border-bottom: 1px #262626 solid;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-name: arrow;
    -webkit-transform: rotate(45deg);
}

@keyframes arrow {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    -webkit-transform: translate(0, 20px) rotate(45deg);
  }
}
<div class="arrow"></div>

  •  Tags:  
  • css
  • Related