skip to Main Content

Html – Automatic font size – js

How do you make font size automatically adjust so that the text doesn't overflow? const h1 = document.getElementsByTagName('h1')[0]; const content = document.getElementById('content'); let size = parseInt(window.getComputedStyle(h1).getPropertyValue('font-size')); while (checkIfOverflows(h1, content)){ size--; h1.style.fontSize = size + 'px'; } function checkIfOverflows(element, parent){ const…

VIEW QUESTION
Back To Top
Search