daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Sep 12th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Find out the effective width of element and resize text in it
  2. <table><tr><td id=txtcell nowrap><span id=txt>My long text is long. My long text.</span></td></tr></table>
  3. <br>Font Size : <span id=mes></span>​
  4.    
  5. #txtcell{ max-width:200px;}
  6.    
  7. var fontSize = 20;
  8. var reduce = function() {
  9.     while ($('#txt').width() > 200) {
  10.         fontSize -= 1;
  11.         $('#txt').css('font-size', fontSize);
  12.     }
  13.     $('#mes').html(fontSize); // this line is only for demonstration, remove it in "production"
  14. };
  15. reduce();
  16.    
  17. td {width: expression(this.style.width);}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top