Adding more pixels to the height of an element does not actually make it larger

Recently, I've been working with material UI and I have a scrolling list of items that I want to resize to be larger. However, I've noticed that no matter how I adjust the height in pixels, the items never exceed 140px.

Below is the code snippet:

  <Box
        display="flex"
        flexDirection="column"
        justifyContent="center"
        height={800}
        overflow={'auto'}
        maxWidth="xl"
      >
        {items.map((item, index) => (
          <Paper
            key={index}
            sx={{ p: 2, height: '200px', width: '75%', margin: '50px auto' }}
          >
            <Typography sx={{ pb: 2 }} textAlign="center">
              {item}
            </Typography>
            <Box>
              {/* Need to create a scrolling container here? */}
              <Grid container spacing={2}>
                <Grid item xs={12}>
                  {/* List of items for this date */}
                  {/* <Item>xs=1.5</Item> */}
                  {/* Button to add items */}
                </Grid>
              </Grid>
              <Button
                variant="outlined"
                key={'addEntry'}
                onClick={addEntry}
                sx={{
                  my: 2,
                  color: 'white',
                  display: 'block',
                  fontFamily: 'monospace',
                }}
              >
                +
              </Button>
            </Box>
          </Paper>
        ))}
      </Box>

Even though I've specified a height of '200px' in the <Paper> component, the items do not exceed 150px. To work around this, I have to remove the height from the enclosing <Box> element, but I prefer to keep my items within it. Could the culprit be the size of the <Paper> element?

Answer №1

The reason for this issue is because the height of your <Box> is greater than the height of the Paper component. Here are a couple of solutions you can implement:

Solution 1 (Setting Box height to 100% and keeping Paper height constant)

<Box
  ...
  height="100%"
  ...
>

<Paper
  ...
  sx={{ p: 2, height: '140px', width: '75%', margin: '50px auto' }}
  ...
>

Solution 2 (Keeping Box height constant and setting Paper height using minHeight)

<Box
  ...
  height="800px"
  ...
>

<Paper
  ...
  sx={{ p: 2, minHeight: '140px', width: '75%', margin: '50px auto' }}
  ...
>

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

Changing opacity of background in Material UI when Drawer is open

Can someone inform me on the steps to adjust the background color and opacity when the Material UI drawer slides open? I have searched the documentation but couldn't find any relevant information. My project is based on React with TypeScript. ...

What is causing the variations in line heights on this webpage?

I have recently created a test webpage, and I noticed that despite using the same CSS style, the line heights are different. This discrepancy is more prominent when viewing the page in Chrome and highlighting the usage of the .instruction class. It appears ...

Providing a base64 encoded file for download using React

I have a base64 string containing the name and content of a PDF file in my REACT app. I'm looking to implement a button that allows users to download the file by triggering the browser's download dialog. The button I am using with REACT-bootstrap ...

Limiting the scope of a CSS style to only apply to a specific element and all of its child

Today, I am encountering an issue with restricting the application of CSS. The <div class="parent"> <div id="childWithNoCss"> <p>No css</p> </div> <div id="childWithCss"> <p>Apply css</p> </div> </ ...

How can I use jQuery to transform a div with its elements into a canvas?

Looking for a way to convert a HTML Div and its elements to canvas, and then the canvas to an image using Jquery. I've checked out a website that only converts the whole HTML page, but I need a solution for converting specific Div elements. Any help w ...

Error in certification encountered in ReactJS when using the Chrome browser

I'm attempting to make an https request from my frontend (reactjs) to backend (nodejs/express). Both of these are running locally. Backend server code: const app = require('./app') const https = require('https'); const fs = requi ...

Firefox: Issue with CSS aspect ratio not being supported in Firefox, unlike Chrome which works correctly

For my application, I am utilizing the display: grid property. My goal is to have the grid items always maintain a square shape by applying an aspect ratio of 1/1. While this works perfectly in Chrome, Firefox seems to ignore the aspect ratio code. Even co ...

Sticky sidebar that adjusts to viewport size in a responsive layout

When designing a CSS fluid layout, most divs utilize percentages to adjust based on the viewport size. However, I have a specific scenario where I need my sidebar to maintain a fixed position. For instance: <aside style="width:25%; float:left; positio ...

Controlling date selection with Material UI's datepicker functionality

I have two date pickers, one for the start date and one for the end date. My goal is to have the end date picker disable all dates prior to the selected start date. For example, if you choose December 15th as the start date, then all dates before December ...

Utilize background-size:cover and incorporate text in a horizontally scrolling webpage

Struggling to create a minimalist HTML layout with a horizontal scrollbar, featuring a large image on the left and a lengthy text with columns on the right? I suspect the issue lies in the implementation of position:relative with float, as well as position ...

Resolving the Material-UI NextJS Button Styling Dilemma

I've encountered an issue with the styling of a few buttons in JS. When I apply a styling class using className, the formatting works fine on the initial render but loses its styling on subsequent refreshes. This problem is specific to two individual ...

Focus on the image displayed through instafeed.js

Using the Instafeed.js plugin to create a dynamic Instagram feed. Everything is working smoothly, but I'm struggling to center the images being retrieved by Instafeed. Despite trying various methods, I can't seem to get it to display as desired. ...

What is the process for inserting a watermark onto an image as it is being retrieved from Firebase?

I am developing a React website where I need to implement a feature that adds a watermark to an image when it is retrieved from Firebase storage. Is there a way to apply a watermark while accessing the image from the storage? I have already looked into Ho ...

Is the NPM Package Manager supported by default when I run the command "npx create-react-app my-app"?

"npx create-react-app my-app" When using this command, a react application is created with the NPM package manager by default. ALSO "npx create-react-app my-app --use-yarn" This command achieves the same result as the one mentioned ab ...

Removing Borders from Dropdown Tabs in Bootstrap Navbar: A Step-by-Step Guide

I am facing an issue while using Bootstrap 4, as I am unable to remove the border that appears when selecting the drop-down tab. Here is a glimpse of the problem You can view the Inspector View here Check out the relevant code snippet ...

Embrace exporting instead of importing everything with an asterisk

I am searching for a method to prioritize exporting over importing for non-default exports. I am familiar with the process for default exports: export ( default as DefaultExport ) from './default_export'; However, does anyone know the correct a ...

Disable automatic focusing for a material-ui popover component

I am struggling to create a search match list that updates as the user types in their query. However, I am facing an issue where the input element loses focus to the pop-up. I have attempted to programmatically set the focus using refs, but I am unable to ...

Can I use Ems instead of pixels for Chrome developer tools?

In all my style-sheets, I opt for using ems instead of px. However, in Chrome Developer Tools, the computed styles/metrics always display in px, even for elements where I specifically used ems: (Here is a screenshot of the computed lengths for a button wi ...

Preventing mouse clicks on checkboxes and triggering events using JavaScript - a complete guide

We have a Table grid with multiple columns, one of which is a Select Box (CheckBox). The expected behavior is that when a row is clicked, the respective CheckBox should get checked, and clicking on the CheckBox itself should update it. I tried implementin ...

Error in ReactJS: TypeError - Trying to convert undefined or null as an object

Here is the affected code with Typescript errors in local. The component name is correct: {template.elements.map((element: TemplateElementModel, i) => { const stand = roomStands?.find( (stand: ExhibitorModel) => stand.standN ...