I currently have a span tag which displays the onclick count for a button. Right now if the number exceeds three digits it will not fit within the span tag. Can I make the span tag adjustable or can I make its width adjustable, so that it will always encompass the onclick count?
I can change the width to accommodate more digits but I would like it to be adjustable because I cannot predict how many onclick events will actually occur.
var counts = {
'Apples': 0,
'Oranges': 0,
'total': 0
};
function countFruit(type) {
document.getElementById('fruitCount').innerHTML = ++counts['total'];
document.getElementById(type + 'Count').innerHTML = ++counts[type];
}
#OrangesCount{
z-index: 20;
position:absolute;
top:70px;
left:45%;
background-color:black;
width:80px;
border:2px solid green;
font-family: 'BPdotsUnicaseSquareBold';
font-size:25px;
color:yellow;
padding-right:4px;
padding-left:4px;
}
#ApplesCount{
z-index: 20;
position:absolute;
color:yellow;
top:70px;
right:45%;
background-color:black;
width:80px;
border:2px solid green;
font-family: 'BPdotsUnicaseSquareBold';
font-size:25px;
}
<a id="buttonright" href="#" onclick="countFruit('Apples'); return false;">
<a id="buttonleft" href="#" onclick="countFruit('Oranges'); return false;">
<span id="ApplesCount"></span>
<span id="OrangesCount"></span>
You just need to remove
widthfrom both css:Here’s JSFiddle