See my demo below. When you click the buttons, the font size changes and this is making the div box grow and shrink. I don't want the box size to change.
How do I prevent this?
$('#button-plus').click(() => {
var currentFontSize = parseInt($('.main > span').css('font-size'));
$('.main > span').css('font-size', currentFontSize + 5 + 'px');
});
$('#button-minus').click(() => {
var currentFontSize = parseInt($('.main > span').css('font-size'));
$('.main > span').css('font-size', (currentFontSize - 5) + 'px');
})
.main {
text-align: center;
width: 200px;
max-width: 200px;
overflow: overflow;
padding: 10px 5px;
border: 2px solid #bbb;
}
.main > span {
font-size: 12px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="main">
<span>Some Text</span>
</div>
<button id="button-plus">+</button>
<button id="button-minus">-</button>