Utilizing Flexbox for uniform card heights

Are you struggling with achieving equal height for multiple project cards? Look no further, as I have a simple solution for you. While trying to make your project cards equal in height, width, evenly spaced, and centered, you might find flex-box helpful. However, getting the equal height part right can be tricky. In my experience, using just a few lines of CSS might not cut it. Let me help you out with that.

In order to assist you better, I would need to take a look at two out of the six articles from your JSX and CSS files. By examining these samples, I can provide insights on how to achieve the desired outcome. Keep in mind that utilizing imported classes from react Material UI can impact the styling of your components.

div {
  text-align: center;
}

article {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  display: inline-flex;
  justify-content: space-evenly;
  align-items: stretch;
  margin: 20px;
  flex-grow: 1;
}
<div>
  <article>
    <Card className={classes.card}>
      <CardActionArea>
        <CardMedia component="img" alt="Workflow Project" height="140" image={WorkFlow} title="Workflow Project" />
        <CardContent>
          <Typography gutterBottom variant="h5" component="h2">
            Work Flow
          </Typography>
          <Typography variant="body2" color="textSecondary" component="p">
            A full stack web application. The front end uses React, Redux, and React Router. The backend uses Firebase. The web application is a way for multiple people to post projects to be seen by all users. It is complete with login/signup, authentication, cloud
            functions, storing all data in a database, and live notifications. It is super Mario themed.
          </Typography>
          <br />
          <Typography variant="body2" color="textSecondary" component="p">
            When visiting the site use the credentials <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a474b5843456a5e4f595e04494547">[email protected]</a> and test1234 to login. Or feel free to make an account.
          </Typography>
        </CardContent>
      </CardActionArea>
      <CardActions>
        <a href="https://work-flow-web-app.firebaseapp.com/" target="_blank" rel="noopener noreferrer">
          <Button size="small" color="primary">
                                Visit Site
                            </Button>
        </a>
        <a href="https://github.com/Amalazing/Work-Flow" target="_blank" rel="noopener noreferrer">
          <Button size="small" color="primary">
                                Visit Code
                            </Button>
        </a>
      </CardActions>
    </Card>
  </article>

  <article>
    <Card className={classes.card}>
      <CardActionArea>
        <CardMedia component="img" alt="Exercise Tracker" height="140" image={MERN} title="Exercise Tracker" />
        <CardContent>
          <Typography gutterBottom variant="h5" component="h2">
            Exercise Tracker
          </Typography>
          <Typography variant="body2" color="textSecondary" component="p">
            This project is a web application that allows multiple people to track and compare exercises. I wrote this project using the MERN stack. I used React for the front end and Node (with Express), MongoDB (Atlas) on the back end. React interacts with the
            Node API using Axios HTTP requests.
          </Typography>
          <br />
          <Typography variant="body2" color="textSecondary" component="p">
            By visiting the video you will be sent to a Vimeo page where you can view the project in action!
          </Typography>
        </CardContent>
      </CardActionArea>
      <CardActions>
        <a href="https://vimeo.com/355889426" target="_blank" rel="noopener noreferrer">
          <Button size="small" color="primary">
                                Visit Video
                            </Button>
        </a>
        <a href="https://github.com/Amalazing/MERN-Exercise-Tracker" target="_blank" rel="noopener noreferrer">
          <Button size="small" color="primary">
                                Visit Code
                            </Button>
        </a>
      </CardActions>
    </Card>
  </article>

Answer №1

If you desire uniform heights for your cards, simply add display:flex to the parent div located above the article element. This will ensure that all sections within the articles have equal heights.

div {
  text-align: center;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
  -ms-flex-wrap: wrap;
}

For a complete example, refer to the snippet below:

div {
  text-align: center;
  display: flex;
  flex-wrap: wrap;
}

div article {
  width: 18%;
  padding: 15px;
}

article {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  display: inline-flex;
  justify-content: space-evenly;
  align-items: stretch;
  margin: 20px;
  flex-grow: 1;
}
<div>
  <!-- Your card components here -->
</div>

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 the alignment of the HTML columns off?

When print-bannertext-left is empty, the print-bannertext-center shifts to the left. How can this issue be resolved? .print-bannertext-left { width: 30%; float: left; } .print-bannertext-center { width: 30%; float: left; margin-bottom: 0.2%; } ...

What are the functioning principles of older ajax file uploading frameworks (pre-html5)?

Traditional HTML includes an input element with a file type option. Tools are available that enable asynchronous file uploads with progress tracking. From what I gather, this is achieved by splitting the file into chunks and sending multiple requests wit ...

Ways to align an inner circle in the middle using CSS

div.container{ border:2px dashed blue; position:relative; } span.parent{ display:inline-block; width:40px; height:40px; border:2px solid black; border-radius:50%; text-align: center; position:absolute; right:20px; top:10px; } span.ch ...

Update the historical record in a NextJs application by using router.replace instead of history entry

We are in the process of building a React/NextJs application and encountering the following situation: Upon arriving at the "Results" page (www.oursite.com/results?someKey=1234-abcd) with specific offers, the user selects an offer. A "Redirect" page is di ...

Using a Django HTML variable embedded within a JSON string

My json string has a variable embedded in it. "country": { "name":"England", "city":"London", "description":"This country has a land mass of {{ info.1 }}km² and population is as big as <span class=\"colorF88017\">{{ info.2 }} ...

JavaScript must be able to detect when the checkbox value is reversed, which is dependent on the user-entered data

Hey there, I come across a situation where users are selecting a checkbox to insert or update a row of data in a MySQL database through SparkJava/ Java. The functionality is working fine except for a minor glitch. The issue arises when the checkbox behav ...

Reset Django password field for changing the password

While implementing a password reset system through email in Django, I encountered an issue. When I input the correct password and confirmation on the password page, it simply reloads the page without taking any action. The form.errors indicate that a field ...

Should GIT be utilized for managing version control of HTML pages?

Currently, I am developing an application that automatically generates blog pages in HTML format using JSON files. In addition to this functionality, the app also needs to support versioning for each blog created. The process involves converting JSON dat ...

Is it possible to automatically redirect to another page once two text inputs have been filled without the use of a button?

Looking to create a basic static demonstration resembling Uber, but struggling to figure out how to trigger a redirect or any kind of action once both input elements have been filled. I plan to include two input fields similar to this example and aim to a ...

Font Family Options for Different Language Versions in Sitecore

I'm working on a Sitecore website that supports multiple languages. I want to customize the font-family for each language based on the user's cookie settings. Is there a way to achieve this? ...

Error: 'require' is undefined in react.production.min.js during production deployment

Greetings! I am encountering some difficulties while trying to build on production: the error "require is not defined" is being caused by react.production.min.js. Below are my webpack.config.js and package.json files: webpack.config.js const path = requi ...

Navigating through an object in React Redux

In my modalProps.rows object, there is a specific structure that I need to use in order to build a select menu. Here is what I have attempted so far: https://i.sstatic.net/0GHPc.png <Select name="replace_id" onChange={handleActivityAreaChan ...

Chrome is having trouble displaying Roboto font correctly

I have been experiencing an issue with the rendering of the Roboto font on a client's website. When I view the site in Chrome (version 43.0.2357.65 m), all the different weights of Roboto appear to look the same. For example, here is a comparison: On ...

Looking to utilize jQuery for writing and reading data to and from a JSON file?

My goal is to create a JSON file and write data to it without any limitations on entries. I also need to be able to read this data from the file and display it on an HTML page, where I can collect the necessary information. As a newcomer to jQuery, I woul ...

inherited background colors are not passed down

I am having issues with applying the background and padding in my CSS. It seems that my CSS is not overriding the Bootstrap styles, and when I apply the container style, the display property is not working as expected. Here is the code snippet: ...

Checking if a start date comes after an end date using Yup - how is it done?

How can I use Yup to validate if the start date overlaps with the end date in a form that creates an event using Formik library? I have two date pickers for choosing the dates and times. I want to display an error message if they overlap. Thanks for the ...

Updating is not allowed during a current state transition, like the one happening in `render` at the moment

Although this question has been asked many times before, I am still struggling to fix my code. It seems like calling setState in this way is causing an issue. I followed the example code from the material-ui website, so this should be easy, right? class ...

Clicking on a React component will result in highlighting

What's the best way to display the selected item after a user clicks on it? <Box py={2}> <Grid container width="330px"> <Grid container direction="column" item xs align="left"> ...

Obtaining a string from a regular expression does not function as anticipated

Currently, I am in the midst of a project that requires me to identify specific HTML tags and replace them with others. To accomplish this task, I am utilizing JavaScript, and the code snippet looks like this: // html to update html = '<div cla ...

Creating a function in React to be passed as a prop

Recently, I was given the task of enhancing a user interface as a small challenge to help me dive into the world of programming. My goal is to incorporate a date picker into my search bar to allow users to filter their search results by selecting specific ...