React application: Issue with second container not adjusting to the full height of the first container

My application consists of two containers. One container is a ReactPrismEditor, while the other is simply a container displaying text.

However, I am facing an issue where the height of the second container does not adjust according to the content inside the first container:

https://i.sstatic.net/zIJAJ.png

Initially, both containers are set to 100vh height. When the content in the first container exceeds this height, the second container should adjust accordingly.

The structure of my code looks like this:

return (
    <AppContainer>
      <FirstContainer>
        <ReactPrismEditor
          ...
        />
      </FirstContainer>

      <SecondContainer>
...
      </SecondContainer>
    </AppContainer>
);

And here is the CSS I have applied:

const FirstContainer = styled.div`
width: 50%;
height: 100vh;
`

const SecondContainer = styled.div`
width: 50%;
height: 100vh;
`

const AppContainer = styled.div`
display: flex;
width: 100vw;
background:#272822;
`

I have tried several solutions including setting heights and positions for the second container, but none seem to work.

  • Tried setting { height: 100%; } for SecondContainer,
  • Tried setting { height: auto; } for SecondContainer,
  • Tried setting
    { position: relative; min-height: 100vh; height: 100%; }
    for SecondContainer
  • Tried setting { position: sticky; } for SecondContainer

None of these solutions yielded the desired result. Any suggestions on how to resolve this issue would be greatly appreciated.

Unfortunately, due to technical difficulties, I am unable to provide a live demo in a code snippet editor.

For further reference, you can inspect the problem area in the following image:

https://i.sstatic.net/XQO2Q.png


UPDATE

I have managed to create a code sandbox with my code. However, due to limitations, the prism editor is not included, resulting in incorrect stretching of the first column. Nonetheless, it may still help identify the issue: https://codesandbox.io/s/smoosh-cherry-7titw?file=/src/App.js

Answer №1

Do you think this solution might work for you?

https://example.com/solution-code

I made some adjustments to the CSS in the code provided to address the issue you mentioned.

Updated version with sticky feature:

You can see the updated result here:

https://example.com/updated-solution-code

In the revised code, I added a new component called StickyItem with the necessary properties for the sticky behavior:

const StickyItem = styled.div`
  padding: 20px;
  position: -webkit-sticky; /* For Safari */
  position: sticky;
  top: 0;
`;

I also adjusted the padding of the Container element to ensure the text remains in place while scrolling. Hopefully, this resolves your concern.

Answer №2

If your issue persists, it could be related to how ReactPrismEditor handles re-rendering after the AppContainer is mounted.

An easy solution would be to apply the background color directly to the AppContainer. For multiple columns, consider giving the AppContainer a striped background.

background: linear-gradient(to right, 
     red 50%, green 50% 75%, yellow 75% 100%);
}

This workaround may not be ideal if you require extensive styling for border lines.

background: linear-gradient(to right, 
     red 50%, green 50% 74.5%, black 74.5% 75%, yellow 75% 100%);
}

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

Establishing a default value as undefined for a numeric data type in Typescript

I have a question regarding setting initial values and resetting number types in TypeScript. Initially, I had the following code snippet: interface FormPattern { id: string; name: string; email: string; age: number; } const AddUser = () => { ...

A snippet of jQuery programming that enables automatic transitions between images

Trying to figure out how to achieve this - I want an image to change every 3 seconds using jquery. Can anyone help me with this? Unfortunately, I haven't been able to find any resources on this specific topic. ...

Dynamic container elements (already arranged)

After creating a marksheet generator, I noticed that the divs positioned over an image on the resulting page are not responsive when trying to print. The print preview ends up looking strange and distorted. How can I make these already positioned divs resp ...

I am facing an issue with MUI DatePicker that is causing issues with rendering in my project. I have also included a

Check out my codesandbox example showcasing MUI's Datepicker in action: https://codesandbox.io/s/proud-pond-fb4rm?file=/src/App.js *Update: I've also included my index.tsx code snippet: import React from 'react'; import ReactDOM from ...

What is the reason behind HTML comment delimiters failing to function within HTML style tags?

Currently, I am utilizing CSS and HTML in my project. To implement styles, I am utilizing both an external stylesheet as well as a "style" element within the HTML to override certain styles. However, I have encountered an issue. When I insert an HTML comm ...

Oops! We encountered an issue with your request, resulting in a status code of 400. This error occurred while utilizing Axios with

Having trouble posting to a mongoDB database while creating a user authentication site using MERN stack. Despite trying multiple solutions, the issue persists with various error messages. Backend is configured using Node.js, Express.js, and MongoDB. Assist ...

Get instant access to the Angular page at your fingertips. Experience the best of both worlds with a hybrid application

Is it possible to create an Angular application that loads only a few pages initially? For example, suppose I have a web application that produces a 25 MB build. Can I separate it and move certain components so they are only loaded when the corresponding U ...

Tips for arranging HTML image sources to prepare for future updates

Incorporated into the HTML are a series of images, each accompanied by text and/or transitions. To streamline positioning, each image set along with other elements (text, video, etc...) is enclosed within a div. Furthermore, every image is labeled with a n ...

Is there a way to automatically update and utilize the access token for a socket connection?

After successfully logging in, I am able to obtain an access token and establish a socket connection. However, I have encountered an issue where the access token does not automatically update itself when the user logs out and back in again. As a result, my ...

Incorporate the key as a prop within a Child Component in a React application

I am trying to display a list of elements in React, where the key of each element is used as an index in front of the item. However, when I try to access props.key, it just returns undefined. Does anyone have any suggestions on how to access the key proper ...

When placed within a <li> element, the <a> tag will not create a hyperlink to a page, but it will

I have encountered an issue with my anchor links. All of them are working properly except for the one in the second ul with an href="page1". Interestingly, the link shows the correct destination at the bottom left of my screen and works when I right-click ...

Updating static files in Django seems to be a bit tricky since clearing the browser cache does not seem to have any effect

I encountered an issue with my Django & React application. While trying to update the appearance of a component, I noticed that Django did not reflect the changes upon refreshing. I attempted to force refresh the page and clear the browser cache without s ...

What could be causing this code to malfunction on jsfiddle?

Why doesn't this code from W3schools work on jsfiddle? I tried to implement it here: https://jsfiddle.net/u6qdfw5f/ <!DOCTYPE html> <html> <title>W3.CSS</title> <meta name="viewport" content="width=device-width, initial ...

What is the reason behind Bootstrap's size classes becoming ineffective after 5?

Consider this: <div class="container m-5"> is effective, while <div class="container m-9"> does not produce the desired result. It appears that any number greater than 5 does not function as expected. What could be the rea ...

Exploring the World of React JS by Diving into Backend Data

Let's consider an application that consists of three pages: "HomePage" "PrivatePage" "UserManagementPage" In addition, there is a file called "BackendCommunication.js" responsible for handling communication with the backend. "Homepage.js" import Re ...

Unable to fetch URLs post the process of uploading files to Firebase

I am facing an issue with my small app that uploads images to firebase and retrieves URLs to display them. Everything works perfectly fine when uploading a single image, but when I try to upload multiple images, it doesn't work as expected. It always ...

Tips for centering the bootstrap navbar on a page

Utilizing bootstrap, I have designed the following navbar: https://i.sstatic.net/shYC3.png This navbar was created using the code snippet below (Bootstrap version 3.3.5): <body> <nav class="navbar navbar-default"> <di ...

Issue with React MUI - Popup not opening when clicking on InputAdornment

I have implemented the Autocomplete component similar to the country example, but with an additional InputAdornment component to display the flag of the selected country. Below is the code that I am currently using: https://codesandbox.io/s/countryselect ...

Using jQuery to extract the value of an object from an <li> element and updating the class attribute of the <li> element

There is a div element: <div id="ddDistr" class="searchBoxSortDistrict" tabindex="1"> <ul id="ddd"> </ul> </div> I have inserted HTML from json into it: $("#ddd").html(" "), $.each(dis, function( index, value) { $("#dd ...

What are some strategies to prevent prior asynchronous effects from interfering with a subsequent call to useEffect?

I have a straightforward component that initiates an asynchronous request when a certain state changes: const MyComponent = () => { const [currentState, setCurrentState] = useState(); const [currentResult, setCurrentResult] = useState(); useEffec ...