Creating an HTML div that fills the remaining height available

Currently, I'm developing a web application and aiming to have the content span the full height of the screen. Is there a way to make the div element (other-child) automatically fill its parent without having to manually set its height?

html {
height:100%;
}

body{
height: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
 }

#parent {
height:100%;
}

#child {
height:50px;
background:yellow;
}

#other-child{
background:red;
/* height: 100% */
}
<html>
<body>
  <div id="parent">
    <div id="child" >fixed height</div>
    <div id="other-child">occupy the rest</div>
  </div>
</body>
</html>

Answer №1

If you utilize css grid on the element with the id of #parent, you can easily manage all the layout from there. It can be as straightforward as the following:

html {
height:100%;
}

body{
height: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
 }

#parent {
 min-height: 100vh;
 display:grid;
 grid-template-rows: 50px 1fr
}

#child {

background:yellow;
}

#other-child{
background:red;
 
}
<html>
<body>
  <div id="parent">
    <div id="child" >fixed height</div>
    <div id="other-child">occupy the rest</div>
  </div>
</body>
</html>

Answer №2

Kindly explore this solution: set the parent element to display:flex and enable the child element to grow using flex-grow: 1

html {
height:100%;
}

body{
height: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
 }

#parent {
height:100%;
width:100%;
display: flex;
flex-grow: 1;
flex-direction: column;
}

#child {
height:50px;
background:yellow;
}

#other-child{
background:red;
flex-grow: 1;
/* height: 100% */
}
<html>
<body>
  <div id="parent">
    <div id="child" >fixed height</div>
    <div id="other-child">occupy the rest</div>
  </div>
</body>
</html>

Answer №3

Here is a suggestion...

html,
body {
  height: 100%;
  margin: 0;
}

#parent {
  display: flex;
  flex-flow: column;
  height: 100%;
}

#child {
  flex: 0 1 auto;
  background: red;
}

#other-child {
  flex: 1 1 auto;
  background: yellow;
}
<div id="parent">
    <div id="child" >fixed height</div>
    <div id="other-child">occupy the rest</div>
  </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to disable the click handler of a div using only classes

Although I'm not an expert in HTML, I am eager to create a basic bootstrap button in HTML that can be enabled and disabled. My question relates to the following scenario: <div class="button" onClick=doSomething >My Button</div ...

Ways to subtly adjust the edges of text in a design

https://i.stack.imgur.com/sr4PF.pngIs there a way to adjust the border of text that already has a border applied? I have successfully created the text with the border using the following CSS: h1 { font-size: 35pt; text-align: center; font-family: ...

Is there a way to ensure that functions operate effectively within a modal window?

While working on a script for my job, I decided to move most of my HTML content into a modal halfway through writing the code. The challenge now is that many functions I've already created no longer work with the content inside the modal. I'm hop ...

Tips for accessing a DOM element's ::before content using JavaScript

Is there a way to retrieve the content of a DOM element's ::before pseudo-element that was applied using CSS3? I've attempted several methods without success, and I'm feeling very confused! // https://rollbar.com/docs/ const links = docum ...

Is it possible to store values in LocalStorage by clicking?

Is there a way to store this value in localstorage whenever the user clicks either up or down??? <script> var Clicks = 800; function UpClick() { Clicks = Clicks + 25; document.getElementById('CountedClicks').innerHTML = C ...

Tips for capturing text input from a Quill rich text editor div

My attempt to retrieve the content entered in Quill editor's editor div using jQuery codes is not proving successful. Although it works for other text inputs, it fails to do so for the editor div. Below is a demonstration of the issue: $(function() ...

Reverting Changes Made with JQuery Append

I have a table where each cell contains a button. When the button is pressed, it adds text to the cell. I am looking for a way to remove this text from the cell when the same button is pressed again. It's important to note that this button appears mul ...

What could be causing my AngularJS to malfunction on this particular website?

I am currently learning AngularJs and practicing some coding. However, I am facing an issue where the javascript code does not work when I run it on my browser (Chrome/IE). The "{{product.like}}" code is not functioning as expected. Is there any specific d ...

What is the best way to include two rows in a single INSERT statement?

For each product that a customer selects to purchase, I have set up a shopping cart to display these items. The requirement is to add each selected product as a separate row in the 'order_details' table with the same customer_id. Screenshot: htt ...

Preserving the most recent choice made in a dropdown menu

Just started with angular and facing an issue saving the select option tag - the language is saved successfully, but the select option always displays English by default even if I select Arabic. The page refreshes and goes back to English. Any assistance o ...

Selenium Webdriver is having trouble locating an element within an xblock

As a beginner in Python, Selenium, and coding in general, I'm not sure if my question even makes sense. My current project involves automating the task of saving edX course webpages as HTML. I am using the latest iPython and Webdriver for this purpos ...

The URL requested exceeds the maximum length limit in asp.net, causing a 414 error

I encountered the issue of receiving an "HTTP Error 414. The request URL is too long." While reading through this article, I learned that it is caused by an excessively lengthy query string: Currently in my web.config, I have set maxQueryStringLength to " ...

The jQuery Bootstrap extension functions correctly on Firefox, but encounters compatibility issues on IE10

My code is based on jQuery 2.1 and bootstrap 3.2. It runs smoothly in Firefox, but encounters issues in IE10. I have added <meta http-equiv="X-UA-Compatible" content="IE=edge"> to the header to address compatibility mode concerns, yet the problem per ...

Styling for Print Media: Adjusting the horizontal spacing between inline elements

I have been developing a custom AngularJS point-of-sale (POS) system that requires printing receipts upon completing a sale. To achieve this, I am using ng-print to print out a sales summary displayed within a specific div element after hiding all other un ...

Setting up a static directory in Node Express to serve index.html along with additional tsv files

I'm encountering an issue with setting up a static folder for a project using the d3 node package. My approach involves using express to host a server.js file, which is structured as follows: var express = require("express"); var app = express(); var ...

Tips on redirecting the user to the page they have selected

<section> <div class="container"> <select name="semester" id="select-semester"> <option value="no-semester">choose a semester</option> <option valu ...

Retrieve the Span class value contained within a Select Option

I realize it may appear repetitive, but it is not. This is the appearance of my select: <select id="avpMy4Y7E4cH_-iIRmmAK6-2GsEOu6Sjr-0-0"> <option value="1Ltr [ <span class=money>Rs.1,495.00</span> ]">...< ...

Javascript continues to execute even after the designated element has been eliminated or substituted

I'm currently working on a WordPress auction site using WooCommerce that needs a countdown timer to display when a specific product auction is ending. Below is the JavaScript code for the countdown timer: const getElem = elem => document.q ...

Determining the size of an object in ASP.net as a percentage of the page, while taking into account the size of

I need help adjusting the size of a silverlight app on a page with multiple banners above it. My goal is to make the app's height always 100% of the screen height minus the banner's height to prevent any scroll bars from appearing. Does anyone kn ...

Optimizing table cell width in ASP.NET based on longest text content

Software: Visual Studio 2010, Asp.Net 4.0 I am working with multiple tables that are stacked vertically on top of each other, all generated dynamically in the codebehind. I would like to ensure that the first column in each table is the same width, based ...