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>
Edited by Mia_K
Link to comment
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

edit this

p {
  text-align: center;
  font-size: 40px;
  margin-top: 0px;
}

to

p#demo {
  text-align: center;
  font-size: 40px;
  margin-top: 0px;
}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • 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.