Created
August 6, 2021 15:34
-
-
Save olafghanizadeh/ea54da75e7b97e128ddc871a36e6560f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getFontSize = (textLength) => { | |
const baseSize = 9 | |
if (textLength >= baseSize) { | |
textLength = baseSize - 2 | |
} | |
const fontSize = baseSize - textLength | |
return `${fontSize}vw` | |
} | |
const boxes = document.querySelectorAll('.content h1') | |
boxes.forEach(box => { | |
box.style.fontSize = getFontSize(box.textContent.length) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment