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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:40:05+00:00 2026-06-05T00:40:05+00:00

Relevant JS Fiddle http://jsfiddle.net/arosen/FMQtR/ Problem My HTML looks something like this: <div id=’parent’> <div

  • 0

Relevant JS Fiddle http://jsfiddle.net/arosen/FMQtR/

Problem

My HTML looks something like this:

<div id='parent'>
  <div id='one'>
    A variable amount of text here.
  </div>

  <div id='two'>
    A less important variable amount of text here.
  </div>
</div>

The #parent div is a fixed height and cannot change. Within it, I have at least two child divs. The first one (or many) will have an unknown amount of text in it determining its height. Based on the content of the first one, I want the last one to take up as much height is left in the parent but not overflow.

My current example CSS is:

#parent {
    border: 1px solid #000;
    height: 150px;
    width: 150px;
}
  #one, #two {
    border: 1px dashed #333;
    height: auto;
    margin: 5px;
    padding: 5px;
    overflow: hidden;
  }

My current JS solution

function() {
  var $two = $('#two');
  var $parent = $('#two').parent()
  $parent.css('overflow', 'hidden');
  var heightDifference = $parent[0].scrollHeight - $parent.height();
  $two.css('height', $two.height() - heightDifference);
}

I’m wondering if there is a CSS layout or HTML solution to this problem or if I must use the JS solution I have in the fiddle that is run on the push of the last button.

EDIT Updated my JS fiddle as the text will not change once on the page but depending on information loaded from the server, will not know how much text it will have until the page is rendered.

EDIT 2 Only modern (and IE 9) browsers need to be supported.

EDIT 3 The final div must have a height as it is used by other jQuery plugins.

  • 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-05T00:40:06+00:00Added an answer on June 5, 2026 at 12:40 am

    No. You can’t. CSS isn’t a programming language. Instead every selector{ property:value; } tuple defines a rule for a specific set of elements. The actual style such as current height, current width or other properties cannot be accessed in CSS.

    Someone might think “what about percentage values”? Well, those are based on the containing block, which is often the parent element (in this case #parent).

    So you either have to specify a fixed height for all div (which isn’t possible according to the information you gave us), or use a JavaScript based solution.

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

Sidebar

Related Questions

I got a CSS question related to this fiddle: http://jsfiddle.net/r584e/ Here the relevant screenshot
See this fiddle: http://jsfiddle.net/Bg9Zx/5/ Relevant code: <fieldset data-role=controlgroup data-type=horizontal id=locate-me> <input type=checkbox name=loc id=loc
In this fiddle http://jsfiddle.net/CBxbT/29/ , if you click the black box, a random color
It's probably easiest to understand by looking at this fiddle: http://jsfiddle.net/TdBdW/1/ - apologies for
I have this code http://jsfiddle.net/xNHKP/6/ (not working in the fiddle for some reason which
Relevent jsFiddle: http://jsfiddle.net/julianlam/eLs9E/ For some reason, given the dataset shown in the fiddle, when
The relevant snippet of HTML: <span class=a> <div class=fieldname>Question 1</div> <input type=text value= name=q1
Here is the relevant HTML: <div class=row> <div class=arrow box>&#9668;</div>Month Year<div class=dayMonth box></div>&#9658;<div class=arrow
The relevant solution and project files for this question are at: http://code.google.com/p/benfwaves/source/browse/trunk/BenfWaves.sln?r=26 http://code.google.com/p/benfwaves/source/browse/trunk/BenfWaves.Library/BenfWaves.Library.csproj?r=26 http://code.google.com/p/benfwaves/source/browse/trunk/BenfWaves.Client/BenfWaves.Client.csproj?r=26
JSFIDDLE HERE If you look at the js fiddle you will find clicking the

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.