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 8116803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:56:51+00:00 2026-06-06T03:56:51+00:00

Consider that we have a DIV with fixed height. Without a defined width ,

  • 0

Consider that we have a DIV with fixed height. Without a defined width, the content will spread to the width of 100%. How to adjust the width to fill the DIV. Definitely, it is not posible with CSS, thus, I am looking for a solution with Javascript.

In this example, the text is spread across the width of 100% and leaves lots fo empty space in the fixed height. I need to set a width of 130px by javascript to fit the content to the entire DIV. But how to calculate the width?

NOTE: This value (130px) was estimated for the example text. Depending on the DIV content, javascript needs to calculate the width required to fit the content within the DIV.

Is there any way to estimate the 2D size of a DIV content?

CSS actually does this for height; when we have a fixed width, it continues the height to fill the DIV. Is it possible to do so for width too?

Clarification: How to vertically fill the DIV without knowing the width (we have a fixed height)?

  • 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-06T03:56:54+00:00Added an answer on June 6, 2026 at 3:56 am

    This is an alternate approach.. While less efficient, it may be more accurate than my other answer.

    see example here:

    Basically loop the width down until the desired height is reached

    <div id="AA">
        <div id='A'>
            I dont know how wide i am, I dont know how wide i am, I dont know how wide i am, I dont know how wide i am, I dont know how wide i need to be
        </div>
    </div>
    

    The CSS:

    #AA {
        height: 300px;
        border: 1px solid black;
        width: 100%;
    }
    
    #A {
       display: inline;
    }
    

    The Script:

        height = $('#AA').height();
    minWidth = 300;
    
    currentWidth = $('#A').width();
    currentHeight = $('#A').height();
    stop = false;
    
    if (currentWidth >= minWidth) {
    
        while (stop === false) {
            if (currentWidth >= minWidth) {
                newWidth = currentWidth - 1;
                $('#AA').width(newWidth);
                currentHeight = $('#A').height();
                currentWidth = $('#A').width();
                if (currentHeight < height) {
                    stop = false;
                }
                else {
                    stop = true;
                }
            }
            else {
                stop = true;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a doubt. Lets consider that we have a div of width 200px. If
i have seen that ajaxStart/ajaxStop always used against a DIV . Consider the following:
I have issue with showing some content in div. I have some text consider
Consider that I have 1 resource and 2 urls (let's say new one and
I have a chat application(Socket Programming) , for that consider I have 2 separate
Assume that we have multiple arrays of integers. You can consider each array as
I have a configuration file that I consider to be my base configuration. I'd
Let's consider we have QWidget that contains QTableWidget (only). So we want to resize
Consider following scenario: I have RESTful URL /articles that returns list of articles user
I have what I would consider a small sized iPhone app that uses SQLite.

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.