Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:48:06+00:00 2026-05-29T09:48:06+00:00

I’m working on a responsive design and I have some display <h3> tags that

  • 0

I’m working on a responsive design and I have some display <h3> tags that I would like to scale down when the width of the browser window is reduced.

The initial setup, based on a width of 960px:

  1. The body font-size is set to 14px
  2. The font-size of the h3 tag is 40px
  3. The width of the containing div is 230px

So here’s what I worked out for the javascript/jQuery:

$(window).resize(function(){
    var containerSize = $('.container').width();
    var textPercentage = 0.17391304347826086956521739130435; /* 40/230 */
    var textRatio = containerSize * textPercentage;
    var textEms = textRatio / 14;

    $('.container h3').css(fontSize,textEms+"em");
});

My javscript skills are obviously quite limited, so I was hoping you could help me get this all purdy and working right. I think the $(window).resize function is the wrong event to use, since the text should resize automatically on page load, not just on window resize.

Thanks in advance for the help!

Note: I don’t want the text to stretch to the edges of the containers, which is why I’m not using FitText.js or BigText.js.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:48:06+00:00Added an answer on May 29, 2026 at 9:48 am

    window.resize is the correct event but it doesn’t fire on page-load. You can however just add .trigger('resize') to your code to make it fire on page-load:

    $(window).bind('resize', function(){
        var containerSize  = $('.container').width(),
            textPercentage = 0.17391304347826086956521739130435, /* 40/230 */
            textRatio      = containerSize * textPercentage,
            textEms        = textRatio / 14;
    
        $('.container h3').css(fontSize, textEms+"em");
    }).trigger('resize');
    

    You are going to want to run this code after document.ready to make sure the width you are getting for the container is correct. You could also place this code at the bottom of your HTML document (which you should do with or without the document.ready event handler) which will make sure the elements are available when you run this code:

    //wait for `document.ready` to fire
    $(function () {
    
        //cache the .container and H3 elements
        var $container = $('.container'),
            $h3        = $container.find('h3');
    
        //bind event handler to `window.resize`
        $(window).bind('resize', function(){
    
            //get the width of the container
            var containerSize  = $container.width(),
                textPercentage = 0.17391304347826086956521739130435, /* 40/230 */
                textRatio      = containerSize * textPercentage,
                textEms        = textRatio / 14;
    
            $h3.css('fontSize', textEms+"em");
        }).trigger('resize');
    });
    

    Notice that I cached the H3 element(s) so it/then don’t have to be selected every resize event, because when you actually re-size your browser there are tons of these events that fire.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.