search

Home  >  Q&A  >  body text

How to create a circular border in CSS where x% is red and the rest is white, where x is a state variable in a JavaScript file?

<p>I'm making a timer app that initially has a white surround around the remaining time in the timer. I want the ring surrounding the remaining time in the timer to gradually turn red, and then turn completely red when the timer runs out. </p> <pre class="brush:php;toolbar:false;"><div className="countdown-timer"> <span>{remainingTime.hours}</span> <span>:</span> <span>{remainingTime.minutes}</span> <span>:</span> <span>{remainingTime.seconds}</span> </div></pre> <pre class="brush:php;toolbar:false;">.countdown-timer { width: 400px; height: 400px; border: 6px solid white; border-radius: 50%; box-shadow: black; font-family: "DM Sans"; font-size: 72px; display: flex; justify-content: center; align-items: center; margin-top: 10px; margin-left: auto; margin-right: auto; }</pre> <p>I tried a concentric circle approach but didn't get the effect I wanted. </p><p>The effect I want is: https://i.stack.imgur.com/AVOz3.png</p><p><br /></p>
P粉482108310P粉482108310496 days ago503

reply all(1)I'll reply

  • P粉111227898

    P粉1112278982023-07-25 14:50:52

    <div>
      {remaining.Time.seconds > X.time?(
      <div className="countdown-timer">
          <span>{remainingTime.hours}</span>
          <span>:</span>
          <span>{remainingTime.minutes}</span>
          <span>:</span>
          <span>{remainingTime.seconds}</span>
      </div>):(
        <div className="countdown-timer2">
          <span>{remainingTime.hours}</span>
          <span>:</span>
          <span>{remainingTime.minutes}</span>
          <span>:</span>
          <span>{remainingTime.seconds}</span>
      </div>
    
      )
      }
    </div>

    ---------------------------------CSS File------------------ -----------------------

    .countdown-timer {
        width: 400px;
        height: 400px;
        border: 6px solid white;
        border-radius: 50%;
        box-shadow: black;
    
        font-family: "DM Sans";
        font-size: 72px;
    
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 10px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .countdown-timer2 {
        width: 400px;
        height: 400px;
        border: 6px solid white;
        border-radius: 50%;
        box-shadow: black;
        border-color: red;
    
        font-family: "DM Sans";
        font-size: 72px;
    
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 10px;
        margin-left: auto;
        margin-right: auto;
    }

    Among them, X.time is a time threshold, beyond which the surrounding ring should remain white, and when less than this time, it will turn red.

    reply
    0
  • Cancelreply