Material React Card Lists

I am facing a simple problem. I want to create a list of cards from left to right. Currently, the card is centered and when I add another card, it appears below the existing ones. I want them to be arranged from left to right.

Please check out the code example on CodeSandbox by clicking on the link below:

CLICK HERE

const useStyles = makeStyles(theme => ({
  root: {
    display: "flex",
    justifyContent: "initial"
  },
  title: {
    marginBottom: "30px"
  },
  header: {
    marginBottom: "20px",
    display: "flex",
    alignItems: "center",
    justifyContent: "space-between"
  },
  card: {
    maxWidth: 300,
    margin: "auto",
    transition: "0.3s",
    boxShadow: "0 8px 40px -12px rgba(0,0,0,0.3)",
    "&:hover": {
      boxShadow: "0 16px 70px -12.125px rgba(0,0,0,0.3)"
    }
  },
  media: {
    paddingTop: "56.25%"
  },
  content: {
    textAlign: "left",
    padding: theme.spacing.unit * 3
  },
  divider: {
    margin: `${theme.spacing.unit * 3}px 0`
  },
  heading: {
    fontWeight: "bold"
  },
  subheading: {
    lineHeight: 1.8
  },
  avatar: {
    display: "inline-block",
    border: "2px solid white",
    "&:not(:first-of-type)": {
      marginLeft: theme.spacing.unit
    }
  }
}));

Answer №1

Material UI offers a fantastic grid system through the Grid component. To use it, simply enclose your cards in a <Grid container> like this:

  <Grid container>
    <Card className={classes.card}>
      ...
    </Card>
  </Grid>

Check out the updated sandbox here.

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

Is there a way for me to retrieve the pageProbs that I have shared with a Component in _app.js?

Upon the loading of my website, I am fetching a large amount of data using getInitialProps. MyApp.getInitialProps = async (appContext) => { // Calls page's `getInitialProps` and fills `appProps.pageProps` const appProps = await App.getInitialProps( ...

What is the purpose of enveloping the BrowserRouter in a parent component as opposed to the routes child component for react router v6?

Attempting to implement the useRoutes hook from [email protected] for creating App routes in JavaScript, I organized my code as follows in routes.jsx: import { useRoutes } from "react-router-dom"; import TestPage from "../Pages/Public/T ...

What factors may be influencing the incorrect behavior of this simple code when using useState()?

In an attempt to replicate a problem I encountered in a larger project component, I have created a simple component. Let's consider the scenario where we have an arrayA and we want to add the value 1 to it on each button click, while also updating ano ...

ReactJS state refuses to update

In my FreeCodeCamp leaderboard table, I have implemented functionality where clicking on the highlighted table header calls different URLs based on sorting criteria. The application either calls https://fcctop100.herokuapp.com/api/fccusers/top/recent or ht ...

Encountering unexpected fetch requests to JSON files when using getStaticProps/getStaticPaths

My webpage seems to be functioning correctly, however I have noticed that in the console there are 5, 404 errors appearing on fetch requests. It's puzzling where these errors are originating from. Interestingly, these 404 errors only occur in the pro ...

Build process in React: Rendering only the index page

After facing errors while trying to deploy my React portfolio site to Netlify via Github, I switched to using NPM Run Build and then uploading the build folder to Netlify. Surprisingly, the home page works perfectly fine, but when I try to navigate to the ...

Ways to insert text inside a border

I'm struggling to figure out how to insert text within a border. Can someone guide me on how to accomplish this? Is there a way to place text in the center of a border? I have included a screenshot for reference. ...

Inadvertent scroll actions causing unexpected value changes in Material UI sliders

I am currently working on a React application that utilizes Material UI, with slider components integrated throughout the interface. However, I have encountered an issue when using a touch screen device - unintentional changes to the slider values occur wh ...

Utilize JavaScript to load an external script at the bottom of the body for improved website performance

On my website, I am utilizing the Mobile ESP script to determine whether visitors are accessing it from a mobile device or desktop. Depending on the type of device, I dynamically load the necessary scripts and CSS stylesheets for optimal navigation. Howev ...

Exploring Array deconstruction and rearrangement in ES6 and React applications

My goal was to reorganize an array within my React container using a destructuring solution, which seemed like a simple task. Here is the initial array: a1 = ['hello', 'hi', 'hola'] componentDidMount() { const { a1 } = this ...

What could be causing the data to not load from the database when the page is loaded?

My current setup involves a button that triggers a specific function upon loading. return ( <> <LikeButtonStyle onLoad={getUserData} onClick={addInfo}> <Image width="10px" height="auto" src="/ ...

How should an iterable be sorted in React?

Let's break down the scenario using pseudo code: {this.props.myIterable.map((iterable) => { return ( <div>iterable.somevalue</div> ) }).sort((a,b) => {return b - a}) To clarify, I am iterating over certain props and displaying ...

What is the best location to insert CSS in an HTML document?

I tried to customize the CSS on my Blogger blog, but unfortunately, I am unable to access the theme designer. As a result, I attempted to add CSS directly into the code using tags. However, I am having trouble locating the tag within the HTML file. This is ...

Issue encountered while managing login error messages: http://localhost:3000/auth/login net::ERR_ABORTED 405 (Method Not Allowed)

I am working on the /app/auth/login/route.ts file. import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' import { cookies } from 'next/headers' import { NextResponse } from 'next/server' export async functi ...

What could be causing the error in my SVG path tag attributes?

Why am I encountering a react error with these attributes? stroke-linecap="square" stroke-linejoin="round" Should they be written as strokeLinecap and strokeLinejoin? <svg width="36" ...

Attempting to simultaneously start my node.js server and React .js app, resulting in the error message 'ERR_MODULE_NOT_FOUND'

Currently facing issues while setting up a server for an ecommerce site being built in React. Attempting to run both the React app and the server simultaneously using npm run dev, but encountering various errors that persist even after attempted fixes foun ...

What could be causing these cards to not show up correctly?

I am currently incorporating Angular Material's cards in a material grid. Here is the code snippet that I am working with: http://codepen.io/anon/pen/YWwwvZ The issue at hand is that the top row of images extends off the screen at the top, and the b ...

Transform routeParams from string to numerical format

Currently, I am working on a straightforward project where I need to retrieve data based on the id number using "routeParams". However, I encountered an issue because the "routeParams" is in string format and I actually need it to be converted to a numbe ...

Encountered an issue while attempting to install the react-twitter-embed package

I've been facing some challenges while attempting to incorporate react-twitter-embed into my react application. Despite trying various troubleshooting steps like deleting and reinstalling the node_modules folder, as well as clearing the npm cache, the ...

"Escape the confines of traditional div sections with the dynamic features of

In the beginning, I have arranged two rows of three divs on my webpage, which is how I intend to use them later. However, when testing the 'mobile view', the divs in the section overflow and move into the next part below the section. This causes ...