2

I'm trying to create swing button with transform rotate property , It's works fine in opera and chrome browsers but in firefox its create weird pixel issue in the border of the button:

Button rendering in Firefox

My css code for button & swing keyframes

.RedButton {
  background-color: #bc0000;
  border-radius: 7px;
  border: 1px solid #bc0000;
  display: inline-block;
  cursor: pointer;
  color: #fff !important;
  font-family: Arial;
  font-size: 30px;
  font-weight: bold;
  padding: 7px 24px;
  text-decoration: none;
  margin-top: 15px;
  animation: swing 5s infinite;
  -moz-animation: swing 5s infinite;
  transition: 0.2s;
  -moz-transition: 0.2s;
}

@-moz-keyframes swing {
  20%,
  60% {
    -moz-transform: rotate(5deg);
  }
  40%,
  80% {
    -moz-transform: rotate(-5deg);
  }

  100% {
    -moz-transform: rotate(0deg);
  }
}

@keyframes swing {
  20%,
  60% {
    transform: rotate(5deg);
  }
  40%,
  80% {
    transform: rotate(-5deg);
  }
  100% {
    transform: rotate(0deg);
  }
}
<div class="RedButton">Get Started Now!</div>

Am i missing something ?

Terry
  • 63,248
  • 15
  • 96
  • 118
domi kp
  • 23
  • 3

2 Answers2

5

adding a tiny shadow make it look better:

.RedButton {
  background-color: #bc0000;
  border-radius: 7px;
  border: 1px solid #bc0000;
  display: inline-block;
  cursor: pointer;
  color: #fff ;
  font-family: Arial;
  font-size: 30px;
  font-weight: bold;
  padding: 7px 24px;
  text-decoration: none;
  margin-top: 15px;
  animation: swing 5s infinite;
  box-shadow: 0 0 1px #bc0000;
}


@keyframes swing {
  20%,
  60% {
    transform: rotate(5deg);
  }
  40%,
  80% {
    transform: rotate(-5deg);
  }
}
<div class="RedButton">Get Started Now!</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
-1

backface-visibility seems to do the work according to this SO thread: css transform, jagged edges in chrome

.RedButton {
   -webkit-backface-visibility: hidden;
   -moz-backface-visibility: hidden;
   -ms-backface-visibility: hidden;
   backface-visibility: hidden;
   // ...
}

If this does not work, try: outline: 1px solid transparent;

geauser
  • 1,005
  • 8
  • 20