Position card action buttons at the bottom using Material UI

I have been working on an app using ReactJS and incorporating MaterialUI (for React) along with React Flexbox.

One issue I've encountered is the struggle to position the card buttons at the bottom, which seems to be a common problem across different frameworks. The specific card component I am utilizing can be found here -> https://material-ui.com/demos/cards/

Despite trying various approaches such as align-items and align-self properties, as well as experimenting with different display types, I have not yet found a solution. Coming from a Bootstrap background, I suspect there might be something I'm overlooking. Thus, I am reaching out for assistance from a CSS expert. Please refer to the image below for context.

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

Additionally, for reference, here is how my code appears in React (where ApiPosts represents my cards component):

<Grid container>
    <Grid item xs={12}>
        <Paper className={classes.paper}>
            <Row className="rowSpacer">
                <Col xs>
                    <Typography variant="title" align="center" color="textPrimary" gutterBottom>
                        Posts are listed below
                    </Typography>
                </Col>
            </Row>
            <Divider />
            <ApiPosts />
        </Paper>
    </Grid>
</Grid>

The layout consists of cards wrapped within '<Row around="xs">' (with 4 posts per row), and each card contained within a '<Col xs></Col>' element.

I appreciate any assistance offered!

Edit: Problem resolved thanks to Ivan's response. Below is the code snippet for anyone who may find it helpful (specifically aimed at Material-UI Cards).

.portCardCl {
    display: flex;
    flex-direction: column;
    height:100%;
}

.portBodyCl {
    display: flex;
    flex: 1 0 auto;
    align-items: flex-end;
    justify-content: center;
    flex-direction: column;
}

.portButCl{
    display: flex;
    justify-content: flex-start;
}

Apply 'portCardCl' to the first '<Card>', 'portBodyCl' to '<CardActionArea>', and 'portButCl' to '<CardActions>'.

Answer №1

Check out this example showcasing the use of css-grid.

const {
  Button,
  createMuiTheme,
  CssBaseline,
  MuiThemeProvider,
  Typography,
  Paper,
  withStyles,
} = window['material-ui'];

const styles = theme => ({
  root: {
    display: "grid",
    gridTemplateColumns: "repeat(4, 1fr)",
    gridGap: "24px",
  },
  
  card: {
    display: "grid",
    gridTemplateRows: "1fr auto",
    gridGap: "8px",
    minHeight: 280,
    backgroundImage: `url(https://via.placeholder.com/100x200)`,
    backgroundSize: "cover"
  },
  
  body: {
    alignSelf: "end",
    textAlign: "center"
  },
  
  actions: {
    display: "flex",
    justifyContent: "space-between"
  }
});

const Grid = withStyles(styles)(
  class Grid extends React.Component {
    render () {
      const { classes } = this.props;
      const cards = [1, 2, 3, 4];
      
      return (
        <div className={classes.root}>
          {cards.map(c => (
            <Paper key={c} className={classes.card}>
              <div className={classes.body}>
                <Typography variant="subheading">
                  Test Image
                </Typography>
                
                <Typography variant="caption">
                  Small help text
                </Typography>
              </div>
              <div className={classes.actions}>
                <Button>Left</Button>
                <Button color="primary">Right</Button>
              </div>
            </Paper>
          ))}
        </div>
      )
    }
  }
)

const theme = createMuiTheme();

ReactDOM.render((
  <MuiThemeProvider theme={theme}>
    <Grid />
  </MuiThemeProvider>
), document.querySelector("#root"))
<script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/@material-ui/core/umd/material-ui.development.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/babel-standalone@latest/babel.min.js" crossorigin="anonymous"></script>
    
    <div id="root"></div>

Take a look at this card example utilizing flex in a simplified manner

.card {
  padding: 24px;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .13);
  background: skyblue;
  border-radius: 4px;
  font-family: "Helvetica", sans-serif;
  display: flex;
  flex-direction: column;
  height: 280px;
  width: 160px;
}

.card__body {
  display: flex;
  flex: 1 0 auto;
  align-items: flex-end;
  justify-content: center;
}

.card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
<div class="card">
  <div class="card__body">
    Test Text
  </div>
  <div class="card__actions">
    <button>Left</button>
    <button>Right</button>
  </div>
</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

Navigation panel positioned on one side filling up the entire content container

I am currently developing a fresh website design. I envision a layout with the header positioned at the top, content in the middle, and a footer that will either stay at the bottom of the window if the content is minimal, or go to the bottom of the content ...

Troubleshooting Problem with React Native Component Mounting During Navigation

Hey there, I'm currently working on a project in React Native and I've run into an error while trying to navigate. Error : I keep receiving the following error: Can't perform a React state update on an unmounted component. This is a no-op ...

Troubleshooting Problems with Adjusting Left Margin Using JQuery

function adjust_width() { $('#cont').toggle(function(){ $('#cont').animate({marginLeft:'0%'}); },function(){ $('#cont').animate({marginLeft:'18.4%'}); }); } The code above is in ...

Positioning an image at the bottom left of the page using absolute positioning is simply not effective

Can anyone help me figure out how to make an image stay just above the footer on the bottom left-hand side of the main content? I've tried using floats, margins, and positioning on left nav elements without success. Here's a link to see what I me ...

Rendering static pages, akin to utilizing getStaticProps, within an app's router on NextJS

After using Next.js for a while, I decided to start a new project using the app router instead of the traditional pages router. With the ability to export getStaticProps in the pages router, I found it very convenient for building pages at runtime, especia ...

Error message: ReactJs is throwing a TypeError due to mod not being recognized as a function

After updating Swiper from version 9.3.2 to 10.2.0, a new issue has arisen in my reactJs project that says TypeError: mod is not a function. ...

Redux-form fails to retrieve the value of the SelectField

I'm trying to work with a simple form using react and redux-form. My goal is to gather all the field values from my form and send them to my RESTful API using jQuery ajax. Unfortunately, I've run into an issue where redux-form doesn't seem ...

An adequate loader might be required to manage this specific file format, which involves loading an image within a React application

I'm having trouble loading an image from my static/images folder, and I keep getting this error message: Avatar.jpg:1 Uncaught Error: Module parse failed: Unexpected character '' (1:0) You may need to configure a loader to handle this file ...

Attempting to deploy to Firebase Hosting by merging into the main branch is resulting in an error message: "Process completed with exit code 254"

I recently deployed my project with Firebase and now I'm encountering an error when trying to merge into the main branch. I've been struggling with this issue for a day now without any luck in resolving it. Below is the detailed error message tha ...

Socket.io event triggering multiple occurrences

I am currently working on a chat application that includes real-time notifications. However, I am facing an issue where these notifications are being sent multiple times rather than just once as intended. My tech stack involves using React on the frontend ...

Is it no longer necessary to bind functions in React Component Classes?

Recently, I observed that when defining normal class component functions in React, there is no longer a need to bind them inside the class constructor. This means that even without using ES6 public class field syntax, you can simply pass these functions to ...

Is there a way to modify the background color with Bootstrap?

While following a Bootstrap tutorial, I stumbled upon an issue that I can't seem to resolve. In my layout, I have an article and a sidebar in a row, with the article taking up 9 columns and the sidebar taking up 3 columns. The background color of the ...

Leveraging Material UI and TypeScript for Effective Styling: Maximizing the Use of !

Currently, I am in the process of developing a React application and incorporating Material UI for my components. One query that has arisen is regarding how to apply an !important property to a style. My attempt at achieving this looked like: <Paper cl ...

Shadow effect is present under every cell in the table row

I am struggling to create an HTML table with proper vertical spacing between rows and a shadow effect beneath each row. Unfortunately, the shadow always ends up overlapping other table content. I have tried adjusting the positioning of elements and setti ...

express-typescript-react: The frontend bundle file could not be located (404 error)

Currently, I am in the process of developing a full stack application that utilizes Express (written in Typescript) and React. One key component of my development setup is webpack, which I'm using to bundle both the backend and frontend parts of the a ...

After attempting to install @mui/system, I encountered an error. I decided to uninstall it, but now I am consistently facing this

ERROR in ./node_modules/@mui/material/Unstable_Grid2/Grid2.js 6:14-25 export 'createGrid' (imported as 'createGrid2') was not found in '@mui/system/Unstable_Grid' (module has no exports). Encountering an issue after installin ...

I can't seem to figure out why this isn't functioning properly

Upon examining the script, you'll notice the interval() function at the very bottom. The issue arises from bc-(AEfficiency*100)/5; monz+((AEfficiency*100)/5)((AFluencyAProduct)/100); For some reason, "bc" and "monz" remain unchanged. Why is that so? T ...

Placing the input-group-addon above the text-input for better positioning

Feeling overwhelmed trying to finalize a simple form due to CSS issues? Check out this image for a visual of the problem: https://i.stack.imgur.com/PgCmN.jpg The label is slightly off to the left, and the button appears larger than the input field. The i ...

Event handler for the MouseLeave event is not successfully triggering when dealing with anchor

When viewing a link to a Codepen, the issue is most noticeable in Chrome: https://codepen.io/pkroupoderov/pen/jdRowv Sometimes, the mouseLeave event fails to trigger when a user quickly moves the cursor over multiple images, resulting in some images reta ...

Guide to making a Material Design Radial effect animation

I am looking to create a unique toolbar effect by following the material design radial reaction choreography guideline. https://i.stack.imgur.com/6oB8r.gif I want to achieve this using an angular 2 transition, but I need some guidance on how to implement ...