So I want to create an animated background, but without changing the background size, because I have problems with my website fit if I change the background-size up to 100 percent in body.

My website will lose his fit.

This is solvable in js?? Here is the code:

  body {
  width: 100wh;
  height: 90vh;
  color: #fff;
  background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
  background-size: 400% 400%;
  -webkit-animation: Gradient 15s ease infinite;
  -moz-animation: Gradient 15s ease infinite;
  animation: Gradient 15s ease infinite;
}

@-webkit-keyframes Gradient {
  0% {
    background-position: 0% 50%
  }
  50% {
    background-position: 100% 50%
  }
  100% {
    background-position: 0% 50%
  }
}

@-moz-keyframes Gradient {
  0% {
    background-position: 0% 50%
  }
  50% {
    background-position: 100% 50%
  }
  100% {
    background-position: 0% 50%
  }
}

@keyframes Gradient {
  0% {
    background-position: 0% 50%
  }
  50% {
    background-position: 100% 50%
  }
  100% {
    background-position: 0% 50%
  }
}

h1,
h6 {
  font-family: 'Open Sans';
  font-weight: 300;
  text-align: center;
  position: absolute;
  top: 45%;
  right: 0;
  left: 0;
<h1>Pure CSS3 Animated Gradient Background</h1>

1 Answers

0
Temani Afif On

Use a pseudo element instead where you can consider a translation animation:

body {
  margin: 0;
  height: 100vh;
  color: #fff;
  position: relative;
  z-index: -1;
  overflow: hidden;
}

body:before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 400%;
  height: 400%;
  background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
  animation: Gradient 5s ease infinite;
}

@keyframes Gradient {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-75%,-75%);
  }
}