Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer night - @850.34
Activity rating: Four Stars Posts & Arts: 50/1k.beats ~ Boop! The forum will close in 150.beats! Random | Recent Posts | Guild Recents
News: :ha: :pc: Hello Melonland! :pc: :happy: Guild Events: There are no events!

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Scale font-size to always fit within container?


« previous next »
Pages: [1] Print Embed
Author Topic: Scale font-size to always fit within container?  (Read 227 times)
voidpain
Newbie ⚓︎
*
View Profile WWW


hello it's me, the Bible! Ive become a human boy!
⛺︎ My Room

Guild Memberships:
Artifacts:
Joined 2026!
« on: a Summer night » Embed

hi! 1rst post here and im asking for help.. typical.

The connundrum: i want to have text within a title card that will change on every page. I figured sorting out a way to have the text scale in size to always fit within the container would save me from having to manually set the font-size on every page.

You can kinda preview what ive already got set up here; https://voidpain.neocities.org/src. the exasperated "broooooooo" would ideally fit most of the horizontal space marked by the bg img behind it. Even when O's are removed or added, the text would shrink or grow accordingly to compensate and still take up most of the space provided.

Ive found some solutions online that demonstrate what i mean; namely this demo of textFit.js (https://codepen.io/chriscoyier/pen/GGQKJE) which ive tried implementing in my code with no luck.

Having failed to get textFit to work, i also found this snippet :

Code
const input = document.querySelector('input');
const output = document.querySelector('.output');
const outputContainer = document.querySelector('.container');

function resize_to_fit() {
  let fontSize = window.getComputedStyle(output).fontSize;
  output.style.fontSize = (parseFloat(fontSize) - 1) + 'px';
  
  if(output.clientHeight >= outputContainer.clientHeight){
    resize_to_fit();
  }
}

function processInput() { 
  output.innerHTML =this.value;
  output.style.fontSize = '100px'; // Default font size
  resize_to_fit();
}

input.addEventListener('input', processInput);

It also resizes the text the way i imagine, but relies on user input to get the text in the first place and i dont want that lol. I dont know enough about javascript to rewrite the code to resize the inner html without all those bells and whistles so any help with that, or pointers as to any other ways i could achieve this would be appreciated.

Thanks melonland :]!

Logged

https://file.garden/aQesLHeiMyzNe4NG/Misc/Gifs/IMG_7639.gif

Artifact Swap: Eugh! What's this?
Tuffy!
Full Member ⚓︎
***
View Profile WWW


⛺︎ My Room

Guild Memberships:
Artifacts:
Lovey DoggoFrom Tuffy with ❤️Met Dan Q on Melonland!Joined 2025!SideEyeDoggo
« Reply #1 on: a Summer night » Embed

Logged

Proud member of the NEW
Forum Revival Movement


Artifact Swap: From Tuffy with ❤️From Tuffy with ❤️
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Zap! Want to Login or Join ? Forum Art Hub Chat Webring Editor Recent Edits Tenement Arcade Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Frutiger Aero Forum Onio Club m15o's Web Services 32Bit Cafe iMood Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers
Minecraft: Online
Join: craft.melonking.net