1
I’m trying to make an animation like this link: https://codepen.io/TheCodeDepository/pen/jKBaoN
It turns out, the code below (which I copied line by line) is with some problem that does not allow animation to start:
section {
width: 100%;
height: 100vh;
background-size: 400% 400%;
background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
animation: mygradient 2s ease infinite;
}
h1 {
position: absolute;
top: 50%;
left: 50%;
font-size: 2em;
letter-spacing: 2px;
text-transform: uppercase;
text-align: center;
color: #fff;
font-family: 'Lato';
border: 1px solid #fff;
transform: translate(-50%, -50%);
padding: 20px;
}
@keyframes mygradient {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
<body>
<section>
<h1>Meu código</h1>
</section>
</body>
Already the code below (copied from the link initially informed) works perfectly. (NOTE: I removed some lines from the original code for finding them unnecessary. So much so that the code works without them).
section {
width: 100vw;
height: 100vh;
background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
background-size: 400% 400%;
animation: Gradient 15s ease infinite;
}
h1 {
position: absolute;
top: 50%;
left: 50%;
font-size: 2em;
letter-spacing: 2px;
text-transform: uppercase;
text-align: center;
color: #fff;
font-family: 'Lato';
border: 1px solid #fff;
transform: translate(-50%, -50%);
padding: 20px;
}
@keyframes Gradient {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
<body>
<section>
<h1>Código Original</h1>
</section>
</body>
As I have been for hours comparing my code that does not work with what works and trying to understand what is wrong, but without result, I decided to ask for help from someone who can help me. I am grateful right now for any response!
If you pass the
background-size: 400% 400%;
to the top line of thebackground: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
namely that thebackground-size
come before the shorthandbackground
the animation fails, because thebackground-size: 400% 400%;
shall cease to apply if it comes before thebackground
– hugocsl
True. I had not attempted it. I even considered it, but I did not believe it would cause such a problem. It is an experience to test all alternatives. Thank you.
– Felipe Maia