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

  • Home
  • SEARCH
  • 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 9233049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:27:36+00:00 2026-06-18T06:27:36+00:00

I have a container, the width of which can change. Withing that container I

  • 0

I have a container, the width of which can change. Withing that container I have couple other elements:

HTML

<div class="box">
    <div style="float:left" class="sub1">
        VARIABLE SIZE FONT
    </div>
    <div style="float:left" class="sub2">
        CONSTANT WIDTH
    </div>
</div>

<div class="box">
    <div style="float:left" class="sub1">
        VARIABLE SIZE FONT
    </div>
    <div style="float:left" class="sub2">
        CONSTANT WIDTH
    </div>
</div>

In most cases I don’t need to do anything with the code, however sometimes the .box div can be narrower. In those cases I need to adjust the font-size of .sub1 container.

JS

 $('.sub2').each(function() {
    parentW = $('.sub2').parent().width(),
    sub_2 = $('.sub2').width() + 10,
    sub_1 = $('.sub1').width(),
    availSpace = parentW - sub_2;

    // below is where I need help 
    while (sub_1 > availSpace) {
       curFontSize = $('.sub_1').css('font-size');
       $('.sub_1').css('font-size', parseInt(curFontSize)-2);
    } 
 });

It seems right but it doen’t appear to work for me. What am I missing?

  • 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-06-18T06:27:37+00:00Added an answer on June 18, 2026 at 6:27 am

    You need to use $(this) inside .each(). Also, you need to access and modify the sub1 div which is with each sub2.

    Try this out:

    $(document).ready(function () {
        $('.sub2').each(function() {
            parentW = $(this).parent().width(),
            sub_2 = $(this).width() + 10,
            div1 = $(this).siblings('.sub1').first();
            sub_1 = div1.width(),
            availSpace = parentW - sub_2;
    
            if (sub_1 > availSpace) {
                curFontSize = div1.css('font-size');
                div1.css('font-size', parseInt(curFontSize)-2);
            } 
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm with a little problem. I have the container div for some elements which
I hope you can help, problem is that I have a table which I
I have a DLL which contains a class with static members . I use
I have a XmlString which contains multiple elements with their nodes. ie <Element> <AccountName>My
I have a page containing a large amount of controls that can trigger postbacks
I'm trying to create a web form that contains checkboxes, among other input elements,
I have a canvas which I draw an image onto. The image can be
I have a fixed width 960px container and I am adjusting my design to
I have an HTML form which contains a drop down, a tinyMCE textarea, and
I have a draggeable image contained within a box. You can zoom in and

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.