I am using a flexbox layout and am trying to get the text in a specific div to be resized to fit that div.
So for example, if I have code as follows:
&l
Here is some code that should do what you are asking.
let size_div = document.querySelector("#font_size");
let div = document.querySelector("#fixed");
while (div.scrollHeight > div.clientHeight) {
let style = window.getComputedStyle(div, null).getPropertyValue('font-size');
let fontSize = parseFloat(style);
if (fontSize <= 1) {
break;
}
div.style.fontSize = "" + (fontSize - 1) + "px";
size_div.innerHTML = " " + div.style.fontSize;
}
You can try it out here: https://codepen.io/lowtex/pen/xNawEO