Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML SUPER-SIMPLE Adding styling & line of text to a countdown timer

jenmc

New Coder
Hi,

Hoping this is really easy to someone who isn't a total newbie to coding!

I've got the following code to add a countdown clock to my site today, but I want to add styling to it to centralise, make bold and size 16pt, plus have "Hurry! Offer ends in:" before it on the same line, but I can't work out what I need to add where - hoping someone can help ASAP?

The paragraph coding on lines 5-11 affected how the rest of the text on the page displayed on my site, so I had to remove them. This styling needs to be self-contained to just this element if possible.


[CODE lang="html" highlight="5-11"][CODE highlight="5-11"]<!DOCTYPE HTML>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

p {

text-align: center;

font-size: 60px;

margin-top: 0px;

}

</style>

</head>

<body>



<p id="demo"></p>



<script>

// Set the date we're counting down to

var countDownDate = new Date("Jan 5, 2022 15:37:25").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 + "h "

+ minutes + "m " + seconds + "s ";



// If the count down is over, write some text

if (distance < 0) {

clearInterval(x);

document.getElementById("demo").innerHTML = "EXPIRED";

}

}, 1000);

</script>



</body>

</html>

[/CODE][/CODE]
 
Hi,

Hoping this is really easy to someone who isn't a total newbie to coding!

I've got the following code to add a countdown clock to my site today, but I want to add styling to it to centralise, make bold and size 16pt, plus have "Hurry! Offer ends in:" before it on the same line, but I can't work out what I need to add where - hoping someone can help ASAP?

The paragraph coding on lines 5-11 affected how the rest of the text on the page displayed on my site, so I had to remove them. This styling needs to be self-contained to just this element if possible.


[CODE lang="html" highlight="5-11"][CODE highlight="5-11"]<!DOCTYPE HTML>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

p {

text-align: center;

font-size: 60px;

margin-top: 0px;

}

</style>

</head>

<body>



<p id="demo"></p>



<script>

// Set the date we're counting down to

var countDownDate = new Date("Jan 5, 2022 15:37:25").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 + "h "

+ minutes + "m " + seconds + "s ";



// If the count down is over, write some text

if (distance < 0) {

clearInterval(x);

document.getElementById("demo").innerHTML = "EXPIRED";

}

}, 1000);

</script>



</body>

</html>

[/CODE][/CODE]
Apologies it's lines 9 to 21 that was causing styling issues.
 
If this is what you want, you can use it and carry on from here -
HTML:
<!DOCTYPE HTML>

<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Counter</title>

    <style>
        .main {
            width: 100%;
            display: flex;
            justify-content: center;
        }
        p {
              text-align: center;
              font-size: 16pt;
              margin-top: 0px;
        }
        p:nth-child(1) {
            color: blue;
            margin-right: 10px;
            font-weight: bold;
        }
        p:nth-child(2) {
            color: red;
        }
    </style>
</head>

<body>
    <div class="main">
        <p>Hurry! Offer ends in:</p>
        <p id="demo"></p>
    </div>

    <script>
    // Set the date we're counting down to
    var countDownDate = new Date("Jan 5, 2022 15:37:25").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 + "h " + minutes + "m " + seconds + "s ";

          // If the count down is over, write some text
          if (distance < 0) {
            clearInterval(x);
            document.getElementById("demo").innerHTML = "EXPIRED";
          }
    }, 1000);
    </script>
</body>

</html>
 

Buy us a coffee!

Back
Top Bottom