Is there a way to make my Material UI cards wrap around the content?

I recently switched my divs to Material UI card components and I'm facing challenges with spacing the cards. In my layout, I have 4 cards within a div and I want them evenly spaced out. Previously, when they were simple divs, achieving this was not an issue.

export default function ({ images }) {
  return (
    <>
      <div className={cardStyles.container}>
        <div className={cardStyles.album}>
          <img className={cardStyles.img} src="yellowCabbin.jpg" />
          <Typography className={cardStyles.description}>
            <h1>Fall Cabbin in Tunisia</h1>
            <p>
              Beautiful cabin in Tunisian countryside by a river. A peaceful place
              surrounded by nature waiting to be explored by you and your family
            </p>
          </Typography>
        </div>
        <div className={cardStyles.album2}>
          {images.map((image) => (
            <Card
              className={cardStyles.card}
              sx={{ maxWidth: 345, m: -0.2, p: 1 }}
            >
              <CardActionArea>
                <CardMedia
                  component="img"
                  key={image.id}
                  image={image.url}
                  alt={image.id}
                />
                <CardContent>
                  <Typography className={cardStyles.description}>
                    <h1>{image.id}</h1>
                  </Typography>
                </CardContent>
              </CardActionArea>
            </Card>
          ))}
        </div>
      </div>
    </>
  );
}
.container{
    display: flex;
    flex-direction: row;
    box-sizing: border-box;
    height: auto;
    width: fit-content;
    /* column-gap: 8px; */
    padding-top:32px;
    margin: 0px 120px 0px 120px;
    /* background-color: brown; */

}

.album{
    display: block;
    width: 80%;
    height: 80%;
    padding: 8px;
    object-fit: contain;
    align-items: center;
    overflow: hidden;
    margin: 0px;
    position: relative;
    z-index: 1;
}
.album2{
    /* padding: 8px; */
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
    width: 50%;
    height: auto;
    position: relative;
}
.card{
    width: 50%;
    position: relative;
    height: auto;
    /* padding: 0px; */
    z-index: 2;
    
}

.img:hover, .card:hover{
    transform: scale(1.3);
    z-index: 3;
    transition-duration: 1s;
    
}

.description{
    position: absolute;
    bottom:10px;
    left: 10px;
    z-index: 2;
    background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,1),70%);

}

@media only screen and (max-width:1000px){
    .container{
        display: block;
        width: 100%;
        margin: 0px;
    }
    .album{
        width: 100%;
    }
    .album2{
        width: 100%;
    }
}

https://i.sstatic.net/gLWag.jpg This is how it currently looks. I prefer if the 4 images on the right are evenly spaced out.

I tried using `sx={m:1}` but it pushed everything into a single column. I also attempted `sx={p:8}`, however, it had no effect.

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

Answer №1

To start, make sure to adjust the height accordingly:

.gallery{
    /* margin: 10px; */
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
    width: 50%;
    height: auto;
    position: relative;
}

Instead of using 'auto' for height, it is recommended to set a specific length since each element has a fixed height of 600px. Include this property:

justify-content:space-evenly

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

Sharing parameters between functions in JavaScript

I have a working code but I want to modify the function getLocation to accept 2 arguments that will be passed to getDistanceFromLatLonInKm within the ajmo function. Currently, getDistanceFromLatLonInKm has hardcoded arguments and I would like to use variab ...

Fill up the table using JSON information and dynamic columns

Below is a snippet of JSON data: { "languageKeys": [{ "id": 1, "project": null, "key": "GENERIC.WELCOME", "languageStrings": [{ "id": 1, "content": "Welcome", "language": { ...

The menu does not appear when I attempt to right-click on the grid header

Is there a way to add a right-click menu to the grid header? The right-click functionality works on Google links, but not on the grid header. Any suggestions on how to resolve this issue? Below is the code I'm using: http://jsfiddle.net/c7gbh1e9/ $( ...

Encountering issues with scope: Unable to retrieve value and receiving an error message stating 'Cannot assign value to undefined property'

var mainApp = angular.module("Main", []); mainApp.controller("CtrlMain", [ function ($scope) { $scope.amount = 545 }]);` var app = angular.module("Main", []); app.controller("MainCtrl", [ function ($scope) { $scope.value = 545 ...

Trouble Aligning Bootstrap Dropdown Menu Link with Other Navbar Links

Issue with dropdown links not aligning properly in the Bootstrap navbar. The positioning seems off and can be seen in the screenshot provided where the blue outline represents the ".dropdown" https://i.stack.imgur.com/QmG7v.png Facing a similar problem a ...

Activate a link, launch a pop-up window, and navigate to the link within the pop-up

I have an unusual idea I'm working on. Let me explain the situation first, and then I'll outline the step-by-step process I want to follow. I currently have a list of items inside a <ul>. Whenever I click on one of these items, I want a mod ...

Unfinished card or cut-off content within a bootstrap accordion

Greetings to the StackOverflow community! I am facing an issue with my accordion and card setup, where the card is not fully displayed within the button at the bottom. The following image illustrates the problem: https://i.sstatic.net/aSFsc.png Here is ...

Tips for maintaining consistent header and footer while developing the front end using JavaScript

Is it possible to maintain the same header and footer on all pages of a website if using JavaScript for the front end and PHP for the back end? While I am comfortable doing this with PHP, I am curious if it can also be achieved with JavaScript or HTML, o ...

A guide on efficiently organizing and refining an array of objects in Vue

I have been working on filtering and sorting an array of objects in Vue. While I have successfully implemented the filtering functionality, I am now looking to incorporate a sorting feature as well. To achieve this, I have set up a dropdown component throu ...

When applying multiple classes with NgClass, use the property name instead of the class content

I am facing a challenge trying to add multiple classes (in this case 2) to a custom component that includes a list item component from MDBootstrap: App.module.ts <custom-list-component size="w-50"> <custom-list-item-component href="#">lis ...

Node JS post route experiencing issues with updating variables within function

I'm in the process of developing an online salon booking system. My goal is to prevent a booking from being made if the salon already has an appointment booked for that day and if the user attempting to make the booking also has an appointment booked ...

Notification will be triggered if the search query falls below x characters in length

Thank you for taking the time to read my query. I am currently working on creating a fancybox search page for a website project. While I have successfully implemented the search results in fancybox, I am facing an issue where clicking on the search button ...

Issues with creating a Dynamic Dependent Select Box using jQuery and PHP

Currently, I am working on a project for my university. The task at hand involves creating four select boxes: Country, State, City, and Course, where the options of three are dependent on the choice made in another. The user's selection will impact th ...

Stripping HTML elements of their identifiers prior to storing them in the database

I have been developing an application that allows users to save their own HTML templates. Users will have access to various HTML components and can create static HTML pages using these components. The content of the page is automatically saved using a Jav ...

Only a select few expandable elements in the jQuery accordion

How can I create an accordion menu with only a few expandable options? I am looking to include the following items in my menu: Home, Support, Sales, Other The "Home" option is just a link without any sub-menu. Clicking on it should direct users to a spec ...

I am running into a problem trying to configure the "timezone" setting for MySQL within Sequelize and Node.js

Currently, I am utilizing node and sequelize to develop a web API. So far, everything is functioning correctly. However, when attempting to update the user table with the following code: var localDate=getDateTime(); console.log(localDate) //output: 2021/06 ...

Redefining the onClick function in the Redux 'presentation' component to include parameters

How can I pass an object as an argument to a function in a redux "presentation component" efficiently? In my <BookList /> container component, I display a <BookListRow/> presentation component for each book. I want to add a button in each Boo ...

Managing images within a bootstrap column: Tips and tricks

I'm using a bootstrap col-md-1 with an image inside, wrapped in a div with padding. The issue is that the image is too small and I want it to be at least as big as the original size, https://i.sstatic.net/9hqyj.png while still being responsive. An ...

Develop a new object using NodeJS within a module for a function

I am working with a file named item.js exports.itemParam = function(name, price, url, id){ this.name = name; this.price = price; this.id = id; this.url = url; }; In my www.js file, I have imported item.js like this: var item = require('../m ...

Encountering a hiccup in the Next.js build process

Warning: The entire page /reservation has been switched to client-side rendering. More info The entire page /properties has been switched to client-side rendering. More info The entire page / has been switched to client-side rendering. More info TypeError: ...