Is there a way to ensure that the height of a component in a grid column adjusts in relation to the heights of the other two components in the

In my layout, there are two columns displayed in a grid. The first column consists of two items (div-1 and div-2), while the second column has only one item (div-3). My goal is to have the height of div-3 adjust based on any changes in div-1 and div-2.

The desired outcome is for both columns to have equal height using the provided css below.

<Grid>
<GridItem>
  <Grid>
   <GridItem >
     <SomeComponent className="div-1"/>
   </GridItem>
   <GridItem >
     <SomeComponent className="div-2"/>
   </GridItem>
  </Grid>
</GridItem>
<GridItem >
  <Grid>
   <GridItem>
     <SomeComponent className="div-3"/> 
   </GridItem>
  </Grid>
</GridItem>
</Grid>

Current css:

.div-1 {
  max-height: 19rem;
  min-height: 6rem;
  overflow-x: hidden;
  overflow-y: auto;
}

.div-3 {
  max-height: 30rem;
  overflow-x: hidden;
  overflow-y: auto;
}

I attempted to use useRef in react but encountered difficulties in passing states between components. Some items require scrollbars to be displayed, and I am trying to find a solution without removing them.

Answer №1

Utilizing CSS grid in this scenario is a classic approach.

While not originally in React, adapting it for your project should pose no major challenges.

<div class="grid">
  <div class="item item1">1<br />asdqwe</div>
  <div class="item item2">2</div>
  <div class="item item3">3</div>
</div>

The key lies within the CSS styling:

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* creating a grid with 2 flexible columns */
}
.item3 {
  grid-row: 1 / span 30; /* ensuring the 3rd item spans all available rows */
  grid-column-start: 2; /* positioning it to appear in the second column */
}

For a demonstration of the code, check out the JSFiddle provided: https://jsfiddle.net/7vga2yqc/2/

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

Conflicting issues arise when serving static files in Django alongside React Router

My website is built using Django for the backend and React.js for the frontend. The React frontend is compiled with react-scripts build to be served as static files by the Django backend. However, when I run the web app with 'python manage.py runserve ...

The Chakra Card component is being displayed in a vertical layout instead of the usual horizontal

I'm currently working on rendering a card and organizing each card in rows of three, with the added flexibility of altering this number responsively. I'm struggling to identify which parts of the code are conflicting with SimpleGrid, and have ex ...

Why is my D3 map not positioning at the center of the page?

Having trouble with centering my D3 map on the webpage. The CSS doesn't seem to apply correctly even though I've tried adding margins to the map class. I'm not sure why the applied CSS isn't working as expected. Could there be somethin ...

How can I display the console log output from JavaScript on an HTML webpage?

If I have a JavaScript function that logs its output in the console using console.log(), is there a way to then export that result into the HTML console? Appreciate any advice on this. ...

Ways to prevent negative values from appearing in the text field

Check out this code snippet on Fiddle. I need help with a text field that should only display positive values. If the input is negative, I want it to be stored in ng-model but not shown in the textbox. function LoginController($scope) { $scope.number = ...

Changing the Color of Hamburger Menu Lines in Bootstrap

How can I change the color of the hamburger menu icon's lines for medium and smaller screen sizes? I have attempted changing it through style attributes and using !important in my CSS file, but so far nothing has been successful. ...

Jquery Error in Bootstrap and DataTables Integration

My knowledge of frontend coding is limited, so please bear with me. Initially, my website was using MVCContrib grid along with its own CSS style. Recently, I switched to Bootstrap which caused MVCContrib to stop working. I've been struggling to integ ...

Displaying specific data based on selected checkbox values in the dataTable

I am currently working with a table using dataTable. Within this table, there is a filter labeled "All" and "Software Engineer." When I click on the label "Software Engineer," the data displayed is appropriate to the label. However, when I click on the "Al ...

Using JavaScript, you can manipulate the position of a line on a canvas to

I want to create a feature where users can manipulate lines on a canvas by skewing them. This means they would be able to drag one end point of the line to a desired point on the same x-axis using JavaScript and HTML5 canvas. Can someone please provide g ...

Having trouble getting the Vue checkbox change event to work?

I am currently utilizing Vue to handle a function that is not triggering on the change event when a checkbox is checked. I am uncertain if the issue lies in the fact that I have placed it within the mounted lifecycle hook or if there is another underlying ...

"Utilizing node.js to create a custom regular expression for removing anchor tags

Can someone provide me with a regex pattern that can eliminate all the a tags from HTML and display the URL as plain text? For instance, take this text: abc <a href="http://a.com" target="_blank">bbb</a> ccccccc After applying the regex patt ...

What strategies can I implement to streamline the use of these functions instead of creating a separate one for each textfield

Currently, I am learning how to use spfx with SPO (SharePoint Online). In my form, there are multiple text fields that need to be handled. I have two class components named A and B. Whenever a textfield in component B is typed into, a function sends the in ...

Conceal the bottom HTML/widget and eliminate the Drag & Drop functionality from the Streamlit file_uploader() feature

I have developed an application using Streamlit that requires the ability to read multiple files simultaneously. To achieve this, I am utilizing the file_uploader() component with the parameter accept_multiple_files=True. I have two queries: Firstly, is ...

Ways to retrieve a QR code through a webpage when operating in offline mode

My goal is to open an HTML file offline, activate QR Code functionality, access the device camera, take a picture of a QR code, and then use the data obtained. The issue arises because attempting to access the device camera from an offline web page requir ...

React-native fails to auto-refresh iOS application in simulator

I am facing an issue with reloading my app in react-native-cli version 1.2.0, react-native version 0.37.0, and watchman version 4.7.0. The problem seems to be related to the index.ios.js file. Below is the code snippet causing the problem: import React ...

I created an image that can be clicked on, but unfortunately it only functions properly on the

I am currently working on creating an image that can be clicked to cycle through different images all within the same frame. While I have managed to get it to work, I am facing a limitation where it only responds to one click. count = 1; function myF ...

Where would you start looking if the right side of a table border is not visible?

Where should I start looking if the right side border of a table element in a div is not visible? ...

Utilizing Bootstrap 4 cards in conjunction with a responsive next/image component

<div className="row align-items-center justify-content-center"> <div className="col-md-3 mt-3"> <div className="card bg-light"> <div className="card-img-top"> <N ...

Determine if the input number exceeds a specified threshold by implementing JavaScript

My attempt at performing calculations on a page is not yielding the desired results. I have tinkered with the code below, but it doesn't seem to be working as expected. Can anyone provide guidance on where I might be going wrong? Specifically, I want ...

The height of the parent div increases as its children grow when the browser is resized

I have a set of three divs aligned horizontally within a parent div. As the browser width changes, one of the child divs wraps under the other two when the width is reduced, transitioning them to a vertical alignment. Here are some visual examples: View i ...