0

I am currently learning HTML/CSS3 basics and I came to the transition/animation chapter. To test my understanding of the subject I threw myself a challenge : create a loading page made out of CSS-only animation.

The charging bar is made of 5 white rectangles with red borders, that go red every 0,1 to show that it is charging, and at the end of the loop go blanck again and repeat.

So I first tried to create an animation white first rectangle's background-color changed to red at 20% of the 0,5s animation and so on... It failed, because I have no clue of how to change multiple element within the same animation. Then I figured that it would be easier to make each rectangle from state "blanck" to state "red" even though it takes a lot more lines of code.

Only problem, as you can see with my code below, the first rectangle doesn't go red whereas the others do, and I can make it go backward at the end.

Could anyone give me a clue about how to make this transition works, then give me a hint/documentation about how to make it works with an animation ?

    <!DOCTYPE html>
<html>
<head>
    <title>Loading</title>
    <link rel="stylesheet" type="text/css" href="loading.css">
</head>

<body>
    <div class="big_div"> 

        <div id="title">    <p class="main_title"> L O A D I N G</p>    </div>

        <div class="carre" id="premiers_carre"></div> 
        <div class="carre" id="deuxieme_carre"></div>
        <div class="carre" id="troisieme_carre"></div>
        <div class="carre" id="quatrieme_carre"></div>
        <div class="carre" id="cinquieme_carre"></div> 


    </div>
</body>
</html>  


 p
        {
            font-family: "Press start 2P"; 
        }

#title {
    position: absolute;
    left : 530px;
    top : 280px ;
}

.big_div
{
    width: 1250px;
    height: 700px;

    display :flex;
    flex-direction : row;
    justify-content: center;
    align-items: center;

}

.carre
{
    background-color: white;
    border:  1px red solid;

    width: 80px;
    height: 10px;
    margin-right: 5px;

}

#premier_carre
{
    transition-property: background-color;
    transition-delay: 0.1s;
}

#deuxieme_carre
{
    transition-property: background-color;
    transition-delay: 0.2s;
}

#troisieme_carre
{
    transition-property: background-color;
    transition-delay: 0.3s;
}

#quatrieme_carre
{
    transition-property: background-color;
    transition-delay: 0.4s;
}

#cinquieme_carre
{
    transition-property: background-color;
    transition-delay: 0.5s;
}

.big_div:hover #premier_carre
{
    background-color: red;

}

.big_div:hover #deuxieme_carre
{
    background-color: red;

}

.big_div:hover #troisieme_carre
{
    background-color: red;

}

.big_div:hover #quatrieme_carre
{
    background-color: red;

}

.big_div:hover #cinquieme_carre
{
    background-color: red;

}
nouse
  • 9
  • 2
  • You have tu use css animation with keyframe. Take a look at this: https://css-tricks.com/snippets/css/keyframe-animation-syntax/ – Germano Plebani Jan 30 '18 at 16:53
  • Which part of the documentation do you reckon is the one that might help me, the multiple animations one ? I'm very confused because I'd like the same @frameworks to take in charge all five of my elements throughout the time : light rectangle_1 then rectangle_2 etc – nouse Jan 30 '18 at 18:06
  • If you want tu repeat the animation, you need to use the keyframe. Here another example from stackoverflow: https://stackoverflow.com/questions/23458640/how-to-have-css3-animation-to-loop-forever – Germano Plebani Jan 31 '18 at 09:23
  • I made a fiddle https://jsfiddle.net/hgphhu1v/ hope this help. – Germano Plebani Jan 31 '18 at 09:36

2 Answers2

0

Bonjour ! You wrote id="premiers_carre" in your code and #premier_carre in your CSS. Simple as that.

Here is your code fixed and improved for a more DRY approach (you defined a class, so why not use it?):

p
        {
            font-family: "Press start 2P"; 
        }

#title {
    position: absolute;
    left : 530px;
    top : 280px ;
}

.big_div
{
    width: 1250px;
    height: 700px;

    display :flex;
    flex-direction : row;
    justify-content: center;
    align-items: center;

}

.carre
{
    background-color: white;
    border:  1px red solid;

    width: 80px;
    height: 10px;
    margin-right: 5px;

    transition-property: background-color;
}

#premier_carre
{
    transition-delay: 0.1s;
}

#deuxieme_carre
{
    transition-delay: 0.2s;
}

#troisieme_carre
{
    transition-delay: 0.3s;
}

#quatrieme_carre
{
    transition-delay: 0.4s;
}

#cinquieme_carre
{
    transition-delay: 0.5s;
}

.big_div:hover .carre
{
    background-color: red;

}
<!DOCTYPE html>
<html>
<head>
    <title>Loading</title>
    <link rel="stylesheet" type="text/css" href="loading.css">
</head>

<body>
    <div class="big_div"> 

        <div id="title">    <p class="main_title"> L O A D I N G</p>    </div>

        <div class="carre" id="premier_carre"></div> 
        <div class="carre" id="deuxieme_carre"></div>
        <div class="carre" id="troisieme_carre"></div>
        <div class="carre" id="quatrieme_carre"></div>
        <div class="carre" id="cinquieme_carre"></div> 


    </div>
</body>
</html>
chriskirknielsen
  • 2,839
  • 2
  • 14
  • 24
0

Well, this is what I have so far for your question:

<!DOCTYPE html>
<html>
 <head>
 <link rel="fluid-icon" href="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Light_Blue_Circle.svg/1200px-Light_Blue_Circle.svg.png" title="HTML">
     
<link rel="mask-icon" href="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Light_Blue_Circle.svg/1200px-Light_Blue_Circle.svg.png" color="#0096ff">

  <link rel="alternate icon" class="js-site-favicon" type="image/png" href="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Light_Blue_Circle.svg/1200px-Light_Blue_Circle.svg.png">

  <link rel="icon" class="js-site-favicon" type="image/svg+xml" href="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Light_Blue_Circle.svg/1200px-Light_Blue_Circle.svg.png"><style>#splash {
        position: absolute; width: 100%; height: 100%; top: 0; left: 0;
        display: flex; align-items: center; justify-content: center;
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: @keyframes loadingColorChange;
      }
      .tw-loaded #splash, #splash-content { display: none; }
      #splash[splash-theme="dark"] { background-color: #303030; color: #303030; }
      #splash-spinner:after {
        content: " "; display: block; width: 64px; height: 64px;
        border-radius: 50%; border: 6px solid; border-color: currentColor transparent currentColor transparent;
        animation: splash-spinner 1s linear infinite;
      }
      @keyframes splash-spinner {
        0% { transform: rotate(0deg); }
        50% { transform: rotate(180deg); }
        100% { transform: rotate(360deg); }
      }
body {
animation-name: bgColorChange;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-delay: none;
animation-name: loadingColorChange;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-delay: none;
}
@keyframes bgColorChange {
0% { background-color: #ea4335; }
12.5% { background-color: #fbbc05; }
25% { background-color: #34a853; }
37.5% { background-color: #4285f4; }
50% { background-color: #34a853; }
62.5% { background-color: #fbbc05; }
75% { background-color: #fbbc05; }
100% { background-color: #ea4335; }
}
@keyframes loadingColorChange {
0% { color: #4285f4; }
12.5% { color: #34a853; }
25% { color: #fbbc05; }
37.5% { color: #ea4335; }
50% { color: #fbbc05; }
62.5% { color: #34a853; }
100% { color: #4285f4; }
}
</style><link rel="dns-prefetch" href="https://trampoline.turbowarp.org/"><link rel="dns-prefetch" href="https://projects.scratch.mit.edu/"><link rel="dns-prefetch" href="https://assets.scratch.mit.edu/"></head><body><div id="splash" aria-hidden="true"><div id="splash-content"><div id="splash-spinner"></div></div></div><script>(function() {
        document.querySelector('#splash-content').style.display = 'block';
        
        try {var localTheme = localStorage.getItem('tw:theme');} catch (e) {}
        if (localTheme ? localTheme === 'dark' : window.matchMedia('(prefers-color-scheme: dark)').matches) document.querySelector('#splash').setAttribute('splash-theme', 'dark');
        
      })();</script><div id="app">Loading...</div><script src="https://turbowarp.org/js/vendors~addon-settings~credits~editor~embed~fullscreen~player.57d02a22479dd55504bc.js"></script><script src="https://turbowarp.org/js/vendors~editor~embed~fullscreen~player.2ebfbf3346f8d17ad60d.js"></script><script src="https://turbowarp.org/js/addon-settings~addons~editor~fullscreen~player.976423b27ac04efde22e.js"></script><script src="https://turbowarp.org/js/editor~embed~fullscreen~player.d227a5ae0c7b2012a7a2.js"></script><script src="https://turbowarp.org/js/player.1fd251802eabb68ba5fe.js"></script></body>
  </body>
</html>
Also all credit to Github