jquery - Programmatically determine Font-Size for single-line display -


I am displaying articles on a page. The title of the article sometimes spreads on two rows, and the second line may contain only one word, it is very undesirable, using JQuery / CSS, to place them on a line, one for programmatic titles What's the best way to set new font-size?

hack of a kind but: something like this will get closer to you, its possibility is slightly more tweeking In, this element clones and the clone text is & amp; Nbsp; so it gets an idea of ​​how much a line's height will be, then the font size of this element decreases, unless this goal is smaller than the height.

Keep in mind that you must attach this function to the parent's size () each task () (var targetHeight = $ (this) .clone () .html ("& Amp; nbsp;") . InsertAfter ($ (this)); while ($ (this) .te ()> targetHeight.height ()) {$ (this) .css ("font-size", parseInt ($ (this.) ("Font-size")) - 1);} targetHeight.remove ();});});


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -