React component that creates a scrollable div and automatically adjusts its height to fill

Currently, I am in the process of designing a layout for my app. My goal is to have the .main__content element fill the available height and scroll if it exceeds that space.

I attempted to wrap the paragraphs within another div but was unsuccessful. Is there a method that would enable me to achieve this desired behavior?

View Demo

App.tsx

function App() {

  const items = new Array(50).fill(null);

  return (
    <div className={style.workspace}>
      <div className={style.header}>header</div>

      <div className={style.content}>
        <div className={style.menu}>menu</div>
        <div className={style.sidebar}>sidebar</div>

        <div className={style.main}>
          <div className={style.tabs}>tabs</div>
          <div className={style.main__content}>
            {items.map((_, index) => (
              <p key={index}>line</p>
            ))}
          </div>
        </div>
      </div>

      <div className={style.footer}>footer</div>
    </div>
  );
}

styles.scss

.workspace {
  width: 100vw;
  height: 100vh;

  display: grid;
  grid-template-rows: 48px calc(100% - 72px) 24px;

  .header {
    background: coral;
  }

  .content {
    display: grid;
    grid-template-columns: 48px 300px calc(100vw - 348px);
    
    background: red;

    .menu {
      background: darkslateblue;
    }

    .sidebar {
      background: darkslategray;
    }

    .main {
      height: 100%;

      display: flex;
      flex-direction: column;

      .tabs {
        height: 48px;
        background: cyan;
      }

      &__content {
        flex-grow: 1;
        background: rebeccapurple;

        display: flex;
        flex-direction: column;

        overflow-y: auto;
      }
    }
  }

  .footer {
    background: yellowgreen;
  }
}

Answer №1

Experiment with adjusting the height of .content and .main to "inherit," while also setting the height of &__content to 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

As the height is expanded, the background color gradually infiltrates the body of the page

I am currently working on an angular application that utilizes angular-pdf. The controller and view function perfectly, and the PDF is displayed correctly, except for one issue. The height of the PDF exceeds the min-height of the module, causing it to expa ...

Header of table remains fixed as user scrolls through data, allowing for easy reference. The left

Above, I have utilized some code from another answer here to display a table. However, I am now contemplating the possibility of customizing it so that the first column remains fixed for horizontal scrolling. Currently, I'm employing the following as ...

The 'fetch' operation could not be completed on the current window due to a TypeError

The error message I am receiving is: TypeError: Failed to execute 'fetch' on 'Window' : The provided value is not of type '(sequence<sequence> or record<ByteString, ByteString>)'. My current challenge involves fetc ...

Issue with reordering columns in Bootstrap 5

Currently, I am transitioning to Bootstrap 5 and facing challenges with the column re-ordering feature. Within my layout, I have three columns: a title, an image, and a paragraph of text. My goal is to display the image on the left, the title on the right, ...

Bug in Cascading Style Sheets affecting Internet Explorer version 6 and version 7

My team is currently facing an issue with our website over at www.eat.vn. While the site functions perfectly on browsers like Firefox, Chrome, IE8 & IE9, and Safari, we are encountering a problem with a key design element when it comes to IE6 and IE7. ...

Updating from React 17 to React 18 in Typescript? The Children of ReactNode type no longer supports inline conditional rendering of `void`

When using the React.ReactNode type for children, inline conditional renders can cause failures. Currently, I am utilizing SWR to fetch data which is resulting in an error message like this: Type 'false | void | Element | undefined' is not assig ...

To access a different page, simply click the link and update the class on the new page

I am facing an issue with the tabs on my homepage. Currently, only one tab with the "current" class is visible while the rest are hidden. Is there a way to link from pageX to my homepage and specify which tab should be open? For instance, when clicking o ...

When using @font-face, Chrome supports it while IE and Firefox do not

I am finding this quite perplexing. I am currently using font-squirrel to download a web kit in order to display a custom font. You can access the font through this link: If you visit the homepage now: The main text in the center reads "Custom Built Webs ...

Adjust an SVG text to fit perfectly within an SVG background rectangle

Inside this box are two SVGs: one for the text and one for the background rectangle. My goal is to make sure the text fits perfectly within the background rectangle without any stretching or overflowing. I don't want to break the text into multiple l ...

Organizing your thoughts: Utilizing Etherpad-Lite's list

Looking to stylize the list items with decimal, upper-alpha, lower-alpha, upper-roman, and lower-roman for each of the first five levels? I attempted to achieve this by adding CSS in my pad.css file. .list-number1 li:before { content: counter(first)") " ...

What could be causing the CSS to not take effect in my Angular project with the Angular Materials Side Nav Bar implementation?

Recently, I delved into the realm of Angular and stumbled upon this tutorial showcasing how to incorporate an Angular materials side nav bar. However, as I followed the instructions laid out in the video, the website displayed did not reflect any CSS styli ...

The issue with the background-size: contain property not functioning properly across different browsers is causing

Hey there! I have created a gallery using a DIV element with a changing background image depending on the preview image or text that is clicked on. Since the pictures in the gallery are of different sizes, I decided to use "background-size: contain". The ...

Is Django_compressor concealing the CSS code?

I have implemented django_compressor in my project. This is how I set it up in my template : {% load compress %} {% compress css %} <link rel="stylesheet" href="/media/css/master.css" type="text/css" charset="utf-8"> {% endcompress %} In my setti ...

"Enhance the Navbar with a pop of color by changing

https://i.sstatic.net/dHKsV.pngMy Navbar is already defined and working perfectly, but I want to add a full-page background to the Navbar links. Currently, on mobile devices, the link backgrounds do not cover the entire page horizontally and instead look l ...

What could be causing the lack of function execution when clicking the button in my Next.js

I am currently working on an application that allows users to create animations with frames saved on a timeline. One of the functionalities I am trying to implement is the ability to delete a frame by clicking a button. However, despite having the correct ...

Tips for concealing the navigation bar during page printing in Bootstrap 5

When attempting to print the page body, I am encountering an issue where the vertical "navbar" continues to display and covers a portion of the content. Below is the code I am using to hide the navbar when printing: @media print and (min-width: 800px){ ...

transform into an array containing objects

I have this item : foodData: { "_id": "603cf063c9f3a13528634bab", "description": "petit déjeuner parisien local sur l'ile", "hotel": "603cd6ae5206ad4f04296218", "nameArticle&quo ...

What happens when you try to access the property 'blur' of something that is undefined?

Example of using ref in Material-UI TextField: <TextField label="Select " value={this.state.type} inputRef={this.selectCar} type="text" /> The selectCar function is set in the constructor as follows: this.selectCar = React.createRef(); When t ...

Ensuring Immutability of React Props in TypeScript

Someone mentioned that React Props are typically read-only, but I noticed that I was able to overwrite the props value in a component without encountering any errors. Is there a way to make props truly read-only? interface Props { readonly isText: bool ...

I'm having trouble getting my footer to stay at the bottom of the page

Struggling to get my footer to stay at the bottom on my blog pages, no matter what I try: Every time the social media section appears, the footer slides up... Can't figure out why... Appreciate any assistance! ...