Skip to content

Instantly share code, notes, and snippets.

@olafghanizadeh
Created August 6, 2021 15:34
Show Gist options
  • Save olafghanizadeh/ea54da75e7b97e128ddc871a36e6560f to your computer and use it in GitHub Desktop.
Save olafghanizadeh/ea54da75e7b97e128ddc871a36e6560f to your computer and use it in GitHub Desktop.
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