Jump to content

How to restrict CSS to be applied only on font size of one element?

Recommended Posts

My countdown counter is messing up my font size. My coding skills are limited, but if I interpret the code right, I think there's CSS inside javascript, and the CSS makes the counter number size as 40 px.  It does however seem to be messing up with the fonts that follow. How could I make it more selective so that it would only be applied to the counter number font size? (This snippet: p { text-align: center; font-size: 40px; margin-top: 0px; }) 

Thanks in advance for any input.

// Set the date we're counting down to
var countDownDate = new Date("Aug 21, 2020 00:00:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  // Output the result in an element with id="demo"
  document.getElementById("demo").innerHTML = days + " d " + hours + " : " + minutes + " : " + seconds + "";

  // If the count down is over, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "We are live!";
  }
}, 1000);
p {
  text-align: center;
  font-size: 40px;
  margin-top: 0px;
}
<!DOCTYPE HTML>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
  <p id="demo"></p>
</body>
Link to comment
  • Replies 1
  • Views 325
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.