Achieving consistent height for Grid items in Material-UI

I'm looking to achieve equal heights for these grid items without distorting them.

Here's the current layout:

This is how I would like it to look:

My challenge is that adjusting the image width manually makes it non-responsive. Since users may replace this image, fixed dimensions are not feasible. Any suggestions are welcome. Here is the essential code snippet (content within the card has been removed for brevity):

Please note: material-ui v4 was used

<Grid container spacing={3}>
   <Grid item lg={12} md={12} sm={12} xs={12}>
      <Grid container spacing={3} className="mb-3">
         <Grid item xs={12} md={3}>
            <Card
               className="justify-between items-center p-sm-24 bg-paper dashboard-card"
               elevation={6}
               >
            </Card>
         </Grid>
         <Grid item xs={12} md={3}>
            <Card
               className="justify-between items-center p-sm-24 bg-paper dashboard-card"
               elevation={6}
               >
            </Card>
         </Grid>
         <Grid item xs={12} md={6}>
            <Card className="bg-paper" elevation={6}>
               <CardContent className="flex justify-center">
                  <img
                  src={this.state.logo}
                  alt="logo"
                  style={{ width: "100%" }}
                  />
               </CardContent>
            </Card>
         </Grid>
      </Grid>
   </Grid>
</Grid>

Answer №1

I found a solution that worked for me, although it may not be the optimal method. Therefore, I am sharing my own answer to my question.

Instead of utilizing an image tag, I opted to use the CardMedia component which allowed me to match the height of other cards and maintain responsiveness.

If you need to display a video or a responsive image, consider using the component prop for these specific scenarios.

<CardMedia
  component="img"
  alt="green iguana"
  height="140"
  image="/static/images/cards/contemplative-reptile.jpg"
  />

For further details, visit: https://mui.com/components/cards/#media

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

Attempting to arrange Cards in a horizontal layout with three items per row using Material UI

Recently, I have started learning Material Ui and ReactJs. My goal is to showcase cards in a horizontal layout with 3 cards per row. However, right now, it's only showing one column. Below is the code that calls the cards: import * as React from &apo ...

Tips for eliminating the left and bottom border in a React chart using Chart.js 2

Is there a way to eliminate the left and bottom borders as shown in the image? ...

Exploring the depths of URL endpoints within ReactJS

Exploring the Star Wars API has been a fun journey for me, but I've encountered some challenges while attempting to fetch Film data from the characters (https://swapi.dev/api/people/1/). const SwapiFilms = (props) => { const [films, setFilms] = ...

Rearrange the characters within the variable before inserting them after

I'm currently dealing with an external system that generates outdated code, however, I do have access to css and javascript. The specific issue at hand involves working with a table that displays each item on a separate row, sometimes resulting in up ...

Building modals with Bootstrap

Currently, my website is built using Bootstrap, JQuery, HTML, and CSS. I am looking to enhance the user experience by incorporating a modal output feature. The idea is that when a user clicks on a specific hyperlink, a modal window will open displaying t ...

mui-datatables: A guide to showcasing customized columns using data from an API

When using mui-datatables, how can I select specific data from my API to display instead of showing all the data returned by the query? [UPDATE: INCLUDING CURRENT CODE] export default function (state = initialState, actions) { switch (actions.type) { ...

Expanding React Material-UI panels with a button click动态添加 Expansion Panel按钮

I'm currently working on a feature where I need to dynamically add an Expansion Panel using React Material UI. Although the panel is added successfully, I'm facing an issue with expanding it (the isExpanded property remains true even when the pan ...

What is the proper way to utilize the router next function for optimal performance

I want to keep it on the same line, but it keeps giving me errors. Is there a way to prevent it from breaking onto a new line? const router = useRouter(); const { replace } = useRouter(); view image here ...

Deploy your React components across a vast array of personal projects

Is this the right place to ask my question? I have created a collection of React components that I want to implement in various personal projects. How can I ensure that when I make updates or improvements to this library, it automatically updates in all t ...

Problems with navigation, not functioning properly due to issues with Pulled functions

I am still getting the hang of things and struggling with the terminology, so please bear with me as I try to explain my issue. Currently, I am working on a project in react native where I have two files - Header.js and footer.js. I have successfully impo ...

What is the correct way to apply styles universally instead of using "*" as a selector?

With Nextron, I was able to successfully run my code, but upon opening the window, I noticed that the body tag had a margin of 8px. Although I managed to change this using the dev tools, I am unsure how to permanently apply this change in my code. When att ...

Struggling to configure dynamic routing in NextJS for endpoints retrieved from Medium API

Having trouble configuring dynamic routing in my Next.js app. I'm attempting to showcase my Medium.com posts using the unofficial Medium API. Currently, I can display a list of cards on the homepage with the posts and each card should link to its corr ...

CSS: Creating a block that stretches the entire width of its parent block

I've been facing the same issue multiple times. Whenever I use the float property to display one block, the next block ends up overlapping with the first one. For example: Consider the following block of code: .row_item{ width: 30%; display: block; ...

Extracting a dynamic parameter from a JSON object

Hey there, I'm new to JavaScript and have been searching for answers online for hours with no luck. I have a question regarding calling an API and receiving the following result: { "return_status":1, "return_message":"success", "data":{ ...

Is there a way to automatically hide divs with the style "visibility:hidden" if they are not visible within the viewport?

Currently, I am working on developing a mobile web app. Unfortunately, Safari in iOS 5.1 or earlier has limited memory capabilities. In order to reduce memory usage while using css3 transitions, I have discovered that utilizing the css styles "display:none ...

Offspring of the superior element resting above another element

I'm dealing with a unique situation involving the Z-INDEX property. Check out my HTML setup below. <div class="player"> <div class="player-line"> <div class="player-handle"></div> <!-- /.player-handle --> </d ...

The concept of vertical alignment within the CSS Grid system

I am attempting to utilize CSS grids in order to vertically align an unordered list. However, I am encountering the following layout: *A******* *B * *C******* ********* * * ********* ********* * * ********* While the grid template rows a ...

When the search is focused, I prefer for the expanding search box to overlay the menu section rather than pushing it aside, all without the use

I am working on a search box with a subtle animation: <input class="search" type="search" placeholder="Search"> To make it expand when focused, I used the following CSS: .search:focus { width: 225px; outline: none; } I also experimented w ...

Take charge of Bootstrap 4 dropdown transformation class while creating a Megamenu

I am currently working on creating a Megamenu using Bootstrap 4's dropdown Component. The issue I'm facing is related to Javascript adding CSS styles with transform, such as transform: translate3d(9px, 5px, 0px); This is causing disruption in m ...

Display the identification or name attribute within the DOM element generated by React Native

While using react native web, I recently integrated a 3rd party tool that requires either an ID attribute or a Name attribute to function properly. Is there a way to make this work seamlessly? For instance, in React Native: <TextInput id="text-i ...