css - Alter text size to fit button width in html -


this question has answer here:

is way in html or css change text size in order fit in button of width changes according container. have 3 buttons of same width, 3rd text little small , 2 letters go out of button if button shrinks.

svg can here. consider following:

<button style="position: relative; width: 400px; height: 200px; ">   <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewbox="0 0 100 50">     <text y="50%" x="50%" text-anchor="middle" font-size="20">foobar</text>   </svg> </button> 

the 20 in font-size="20" refers coordinates specified viewbox, font size 1/5 (20/100) of size of button. of course, not precisely solve problem of ensuring text fits in button, if have general idea of number of characters, can choose font size such that number of characters fit.

enter image description here


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -