{"id":404,"date":"2012-06-15T07:42:41","date_gmt":"2012-06-15T07:42:41","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=404"},"modified":"2022-02-17T07:14:47","modified_gmt":"2022-02-17T07:14:47","slug":"making-text-fit-a-box","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/text\/making-text-fit-a-box","title":{"rendered":"Making Text Fit A Box"},"content":{"rendered":"<h5>JavaScript<\/h5>\n<pre><code>\r\n<&lt;script type=\"text\/javascript\"&gt;\r\n$.fn.textfill = function(options) {\r\n    var fontSize = options.maxFontPixels;\r\n    var ourText = $('span:visible:first', this);\r\n    var maxHeight = $(this).height();\r\n    var maxWidth = $(this).width();\r\n    var textHeight;\r\n    var textWidth;\r\n    do {\r\n            ourText.css('font-size', fontSize);\r\n            textHeight = ourText.height();\r\n            textWidth = ourText.width();\r\n            fontSize = fontSize - 1;\r\n    } while (textHeight &gt; maxHeight || textWidth &gt; maxWidth &#038;&#038; fontSize &gt; 3);\r\n    return this;\r\n}\r\n\r\n$('div#my_text_box').textfill({ maxFontPixels: 100 });\r\n<&lt;\/script&gt;\r\n<\/code><\/pre>\n<h5>CSS<\/h5>\n<pre><code>\r\n#my_text_box {\r\n    border: 1px solid red;\r\n    height: 50px;\r\n    width: 70px;\r\n}\r\n<\/code><\/pre>\n<h5>HTML<\/h5>\n<pre><code>\r\n&lt;div id=\"my_text_box\"&gt;\r\n    &lt;span&gt;Hello World&lt;\/span&gt;\r\n&lt;\/div&gt;\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[],"class_list":["post-404","post","type-post","status-publish","format-standard","hentry","category-text"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=404"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":1435,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/404\/revisions\/1435"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}