What is the best way to allocate the remaining space to one div while setting the first div to 20vmin?

I am facing a challenge with two div elements in my design. One of the divs has been set to have a height of 20vmin, but I am struggling to make the other div take up the remaining height.

Initially, I experimented with using 80vmin for the second div, however, this did not consistently result in it taking up the entire remaining space.

Another attempt involved setting the height of the second div to 80%, but this also failed to accurately occupy the remaining space as desired.

Answer №1

When using grids, it is important to understand the concept of "the remaining space" with the use of fr units. To address this issue, you can style the parent container of your div elements as display: grid. Start by setting the height of the first div and applying auto size to the first grid row. Then, set the size of the second grid row to 1fr, allowing the second div to expand and occupy the entire row.

body, html {
  height: 100%;
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  margin: 0;
}

.d1 {
  border: 5px solid blue;
  height: 20vmin;
}

.d2 {
  border: 5px solid red;
}
<div class="d1"></div>
<div class="d2"></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

Adjust the height of the div element to match the screen height with AngularJS controller

Can someone please assist me in resolving this issue? I'm currently working on a div element that displays data (positioned on the left side of the screen). I want to add a scrollbar exclusively to this div. I managed to achieve this by using the fol ...

When using the HTML a tag, it can create unexpected gaps and

I have a sentence written in PHP that I've separated into individual word components using the explode function. foreach ($words as $splitword) { echo $splitword; /* echo "<a href = 'word.php?word=" . $splitword . "'>" . $spli ...

Switching the background image when hovering over a list element

Looking at the screenshot, it's clear that there is an unordered list with a background image set on the div. What I am trying to achieve is to have the background image change whenever I hover over a list item. Each list item should trigger a differe ...

Tips for adding a red dot at the top-right corner of a necessary HTML input label, similar to an asterisk

Is there a way to replace the asterisk with a dot in an HTML label for a required input? The dot should be positioned in the top-right corner similar to where the asterisk would typically be. ...

Are CSS animations still triggered even when the element is not visible?

I currently have a loading indicator element that is consistently displayed on my webpage. It can be shown or hidden by adding or removing a specific class that adjusts its opacity and z-index. The element itself contains an image with a CSS animation. My ...

Perfectly aligning when the width is undetermined

When centering elements with dynamic widths, I typically use the code below: .horz-vert-center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); } However, a common issue I face is that the element resizes prematur ...

Tips for placing an image in the bottom right corner of a frame

My goal on the Roman Numismatics page is to place the yellow 'bid' button at the lower right corner of each frame. Current code <p><a href="<?= $product->page_url() ?>"><img border="0" alt="Bid&qu ...

Using CSS sprites to style text links

I've been attempting to incorporate an image with various icons for text links in an unordered list, but I can't seem to display just one icon with some space next to it for the text. The code I have so far is: http://jsfiddle.net/XyVtq/2/ This ...

Issues with @material-ui/core and react-bootstrap imports are causing disruptions to the NextJS build process

After researching, I've come to realize that this issue is common among developers. Unfortunately, none of the solutions I found have worked for me. During npm run dev mode, everything in the project functions as expected, with all imports working se ...

Adjust the height value of each element to match the maximum height within a single line using only CSS

There are 3 divs styled with display:inline-block. I aim to adjust their height values so they match the highest one. The desired effect is demonstrated visually below. Is it doable using only CSS? ----- ----- ----- ----- ----- ---- ...

mapping buttons to images based on dynamic conditions

In my folder, I have over 1000 files. Using opendir, readdir, and is_dir, I can display the thumbnails of these files in my browser. Each thumbnail also has a corresponding button assigned to it. What I'm looking to do now is delete the 500th image wh ...

Tips for updating the background color of a specific row

I have a piece of code that I am trying to modify with a specific condition. If {row.BB} is less than or equal to 100, I want to change the background color of the row with this value to red. Can someone help me achieve this? The code is linked to a data ...

The <hr> tag is not displaying properly within the <option> element

I'm facing an issue with a selection element in my Vue project <div class="resultContainer"> <section> <option class="resultBtn" v-for="exchange in finalExchanges"> {{exchange}} <hr></option> </section> ...

The issue with the Angular custom checkbox directive arises when using it within an ng-repeat

A personalized directive has been developed for checkboxes that is applicable throughout the application. The code for creating the checkbox is as follows: JS angular.module("myApp") .component("ngCheckbox", { template: '<di ...

Loading an animated SVG sprite file in real-time

Recently, I received an SVG sprite file from our designers to use in my app. The specified convention is to load the sprite at the top of the <body> element and then render icons using a specific code snippet: <svg class="u-icon-gear-dims"> ...

Tips on customizing a row in a table

Having a small issue styling a row in my table. Essentially, the table consists of 4 rows. a) If the data under column Title 5 is below 0, then the entire row should display in red color. b) If the data under column Title 5 is equal to 17, then the compl ...

Unveil a portal to the identical webpage

My apologies for my English skills... Could anyone advise me on how to display an image? Hello, I am looking for a way to have a small window open on my site when a user clicks on the zoom icon, where I can describe a product. Any guidance on the HTML co ...

Overlap of Navigation Bar and Carousel

Encountering an issue. I recently made a modification to my website in hopes of integrating a full-width carousel instead of a jumbotron. However, there seems to be a problem as my navbar is overlapping the jumbotron section along with the caption and oth ...

Positioning two images alongside text

I am trying to position two images at the top of my website so that they align correctly with the text next to them. However, I've encountered a few challenges: 1) The text doesn't have any spacing between the images. 2) The text varies in le ...

Prevent body scrolling on Mobile Safari by using JavaScript

My goal is to prevent the body of my page from scrolling altogether when a modal overlay is open. The modal occupies the entire screen ({position: fixed;top:0;left:0;right:0;bottom:0;}) and has its own scroll functionality. However, upon reaching the end ...