0

I'm trying to make the words always occupy 90% of the space of a box, but the problem arises when I don't know the size of these words, as they will be written by the user and taken from the DB.

How do I make a first name always take up 90% of 300px, for example?

<style>
.box{width:300px}
.txt{font-size:90%} /* HERE IS THE QUESTION*/
</style>
<div class="box">
<span class="txt"><?php echo $r['txt_db']; ?></span>
</div>

I found something about it, but nothing definitive, just improvisations that have many flaws.

Rafael
  • 23
  • 4
  • try applying `max-width: 300px` to the first name-element. this way, it will scale between 1-300px depending on how many characters is in the first name-element. `font-size` is used for declaring each individual letters font-size, not how much width it should take – Sigurd Mazanti May 14 '22 at 06:28
  • https://stackoverflow.com/a/19818026/13102310 – TorNato May 14 '22 at 07:25
  • Is using JavaScript possible? – A Haworth May 14 '22 at 07:51

0 Answers0