Working on a app that requires a count up and have chosen the font Orbitron
for its square look.
The problem being that,unlike the default font on chrome, the width of this font's digit isn't fixed, meaning that the count characters will move left and right depending of the size of the digits being displayed.
Here's the problem illustrated in a fiddle: https://jsfiddle.net/qc863hc4/8/
Only solution I found so far is to separate the two digits into two different div
s so that their position is calculated independently, but it seems over-complicated.
Is there any way to fix the width of the characters of the <p>
?
HTML
<body>
<link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet">
<div class="countainer">
<p class="count">00</p>
</div>
<button>
count++
</button>
</body>
CSS
.countainer{
width : 100px;
height : 50px;
border: 2px solid black;
font-size: 40px;
text-align : center;
letter-spacing : 15px;
text-indent : 10px;
font-family : "orbitron";
}
.countainer p {
margin : 0;
}
JS
var count=0
var button = document.querySelector("button");
var p = document.querySelector("p");
button.addEventListener("click",function(){
count++;
p.innerHTML = ("0" +count).slice(-2);
})