Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Resizing Text to window
    primarykey
    data
    text
    <p>I am using <code>em</code> units for my text, however, it doesn't seem to work. In huge width screen resolutions, the text is not wide/big enough to fill the screen, in small screen resolutions, it wraps. How can I control this?</p> <p>Basically, it would be nice if I could control the size of the text based on the actual windows size. So that, if the window gets resized down and/or up, the text accomodates for it, and the layout should look the same at all times (in all browser screen widths).</p> <p>How can I do this? Have been playing with the jQuery resize event, but not sure how I can use it for my purpose. Maybe someone can get me started in the right direction here?</p> <p>The following is an example of a jsFiddle that does this: <a href="http://jsfiddle.net/vqbCL/2/" rel="nofollow">http://jsfiddle.net/vqbCL/2/</a></p> <p>But, that is for table elements, I'm not using any table elements. Trying for a fluid layout. So, would be nice if I could incorporate that technique on font sizes of all elements on the page.</p> <p>Here is the code I am using in a feeble attempt at trying to do this:</p> <pre><code>jQuery(document).ready(function($){ $(window).bind("resize", function(){ var containerSize = $("body").width(), bodyFontSize = $("body").css("font-size"); textPercentage = parseInt(bodyFontSize.substring(0, bodyFontSize.length - 2)) / $("body").width(), textRatio = containerSize * textPercentage, textEms = textRatio / parseInt(bodyFontSize.substring(0, bodyFontSize.length - 2)); alert("Text Percentage = " + textPercentage + "\nTextRatio = " + textRatio + "\nNew EM font-size = " + textEms); $('body').css('fontSize', textEms+'em'); }).trigger("resize"); }); </code></pre> <p>What is happening here is this:</p> <pre><code>containerSize = 974 (might be different for you depending on your browser width). bodyFontSize = 16px textPercentage = 16/974 = 0.01642710472279261 textRatio = 974 * 0.01642710472279261 = 16 textEm = 16 / 16 = 1em; </code></pre> <p>Need to determine how to get the proper textRatio and get the proper textEm from that.</p> <p><strong>* Updated to newest code above *</strong></p> <p>You can see me trying to implement this here: <a href="http://dream-portal.net/Test/index.html" rel="nofollow">http://dream-portal.net/Test/index.html</a></p> <p>Basically, the Text Ratio (16 pixels) and the EM Font-Size is always 1em (they are always the same), however, the only thing that changes here is the <code>Text Percentage</code> on window resize. But the font-size is always 1em and Text Ratio always = 16 (as in 16 pixels, which is the <code>body.css("font-size")</code> value. There must be some sort of flaw in the formula for calculating this somewhere.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload