Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Find out the effective width of element and resize text in it
- <table><tr><td id=txtcell nowrap><span id=txt>My long text is long. My long text.</span></td></tr></table>
- <br>Font Size : <span id=mes></span>
- #txtcell{ max-width:200px;}
- var fontSize = 20;
- var reduce = function() {
- while ($('#txt').width() > 200) {
- fontSize -= 1;
- $('#txt').css('font-size', fontSize);
- }
- $('#mes').html(fontSize); // this line is only for demonstration, remove it in "production"
- };
- reduce();
- td {width: expression(this.style.width);}
Add Comment
Please, Sign In to add comment