jquery - resize font to fit in a div (on one line) -
Similar questions have been asked, but do the solutions with what I am trying to do. Actually, I have an article with a title ( & lt; h1 & gt;
). I do not want to control the length of the title, but I also do not want the title to appear on multiple lines . & lt; Div & gt;
Is there a way with CSS or jQuery to change the size of the text depending on the width of the tag?
I know what I will do with the pseudocode if I & lt; Div & gt;
:
var fontize = $ ("# title"). Overlap the text on the edge of CSS ("font-size"). ; Var i = / * Delete unit * from the integer / while (/ * text overlap div * /) {$ ("# title") CSS ("font-size", - "+" pt ");}
If there is a CSS attribute, then I can determine that it will also be good, but I do not
css no, javascript yes
There is no way you can use this CSS, but you can do this in javascript / jquery to help with your pseudo code. Because you already know what to do, it is just that you do not know how to know the extra width.
The best way to be DIV with the following (at least) style:
Status: full; visibility: hidden; white spot: abrop; font-family: / * like your title * /
then your text By copying and setting some initial font size, you can set the loop of your time. You can do it again and stop when the width of the divis is appropriate. Then set the calculated font size to your original title.
In this way this probe will be hidden from the user's eyes and hence it will work faster.
BTW : This is a general way of how the auto is moving textarea
script works with the same style settings as the original text field. And use the text to adjust the height of the user type. The text field can be very few in the first place but if the user types in several lessons then it will automatically grow to adjust the content.
While loop optimization
you can optimize to reduce your time
Comments
Post a Comment