How can I ensure that a button remains fixed at the bottom of a Material UI React Component?

I am currently working on developing a layout for a web application, and I have encountered an issue that I am struggling to resolve.

The structure of my grid is as follows:

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

My goal is to ensure that each section inside the card starts at the same point.

For example, the icons are correctly aligned as their tops match up.

The titles also appear fine since their tops are aligned.

However, the content text is not properly aligned across the three cards as their tops do not align.

Additionally, the "learn more" buttons should be aligned and ideally positioned at the bottom of the card. Currently, they are displayed at different heights.

The code I have written so far is outlined below:

HomeGrid.jsx:

import React, { useState, useEffect, Fragment } from 'react'

import { useStyles } from '../styles'

import SimpleCard from '../card/SimpleCard'

import { Grid, Container, Paper } from '@material-ui/core'
import QuestionAnswerIcon from '@material-ui/icons/QuestionAnswer'
import FindInPageIcon from '@material-ui/icons/FindInPage'
import AccountBalanceWalletIcon from '@material-ui/icons/AccountBalanceWallet'

const HomeGrid = () => {
    const classes = useStyles()
    return (
        <Container disableGutters className={classes.homeGridContainer}>
            <Grid
                alignItems="stretch"
                alignContent="center"
                justify="center"
                wrap="wrap"
                container
                spacing={10}
            >
                <Grid item xs={12} md={4} align="center">
                    <SimpleCard
                        icon={<QuestionAnswerIcon fontSize={'large'} />}
                        title={'Speak'}
                        content={'Speaking to someone can help blah blah'}
                    ></SimpleCard>
                </Grid>
                <Grid item xs={12} md={4} align="center">
                    <SimpleCard
                        icon={<FindInPageIcon fontSize={'large'} />}
                        title={'Finding someone like this example can be great'}
                        content={'Finding to someone can help blah blah'}
                    ></SimpleCard>
                </Grid>
                <Grid item xs={12} md={4} align="center">
                    <SimpleCard
                        icon={<AccountBalanceWalletIcon fontSize={'large'} />}
                        title={'No Fees Here'}
                        content={'No Fees shalt find thou'}
                    ></SimpleCard>
                </Grid>
            </Grid>
        </Container>
    )
}

export default HomeGrid

SimpleCard.jsx:

import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import Card from '@material-ui/core/Card'
import CardActions from '@material-ui/core/CardActions'
import CardContent from '@material-ui/core/CardContent'
import Button from '@material-ui/core/Button'
import Typography from '@material-ui/core/Typography'
import { CardActionArea, CardMedia } from '@material-ui/core'

import QuestionAnswerIcon from '@material-ui/icons/QuestionAnswer'

const useStyles = makeStyles({
    simpleCard: {
        minWidth: 275,
    },
    bullet: {
        display: 'inline-block',
        margin: '0 2px',
        transform: 'scale(0.8)',
    },
    title: {
        fontSize: 14,
    },
    pos: {
        marginBottom: 12,
    },
})

const SimpleCard = (props) => {
    const classes = useStyles()

    return (
        <Card style={{ height: '100%' }}>
            <CardContent>
                {props.icon}
                <Typography variant="h6" component="h2">
                    {props.title}
                </Typography>
                <Typography variant="body1" component="p">
                    {props.content}
                </Typography>
            </CardContent>
            <CardActions className={classes.actions}>
                <Button size="small">Learn More</Button>
            </CardActions>
        </Card>
    )
}

export default SimpleCard

I have attempted to implement the solution provided in this answer: enter link description here, but it does not seem to work as expected.

Could someone please offer guidance or assistance with this issue?

Answer №1

Applying the flex property can resolve this problem.
Simply assign the flex styles

display:'flex', justifyContent:'space-between', flexDirection:'column'
to the Card component.
This will move the buttons of all the Cards to the bottom of each card.

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

What happens when you click and trigger mouseleave?

window.onload = function() { $(".compartir").hover(function() { console.log('hover'); var self = this; setTimeout($(self).addClass('ready'), 500); }, function() { var self = this; console.log('leave'); ...

Instructions for implementing personalized horizontal and vertical scrolling within Angular 9

I am currently working on an angular application where users can upload files, and I display the contents of the file on the user interface. These files may be quite long, so I would need vertical scrolling to navigate through them easily. Additionally, fo ...

Retrieve specific elements from an array based on the other elements present in the array

I am working with a result set that consists of various combinations from the following data structure: [ ["1st", "FELONY"], ["2nd", "FELONY"], ["3rd", "FELONY"], ["1st", "MISDEMEANOR"], ["2nd", "MISDEMEANOR"], ["3rd", "MISDEMEANOR"]] For example, it co ...

What is the best way to ensure that any words exceeding the line length automatically move to the next line?

My webpage width is currently set to 100vw and adjusts responsively as the viewport size changes. However, there seems to be a slight issue where certain words overflow without being pushed to the next line, causing a small horizontal scroll: Upon slight ...

Converting a JavaScript object into JSON format

I am currently working on serializing a JavaScript object to JSON. Here is the code I have written so far: var info = {}; ... $.each(data, function (key, value) { info["name"] = value.name; info["id"] = value.id; ...

What is the appropriate interface for determining NavLink isActive status?

In the process of crafting a "dumb" component using NavLink, I am defining the props interface for this component. However, I encountered an issue when trying to include isActive in the interface. It's throwing errors. I need guidance on how to prope ...

We were unable to locate an available port at xxx.heroku.com

I'm in the process of deploying a react frontend on Heroku. Initially, I encountered an "Invalid Host Header" error due to using the proxy in my package.json file. To address this, I created a .env.development file and specified the Host to my Heroku ...

Expanding <a> element to cover the entire <li> container

Take a look at this straightforward menu layout: <ul id="menu"> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> </ul> I'm looking to expand the <a> element so that it ...

extracting content using cheerio

I need help extracting specific information from this HTML and storing it in an object. I only want to extract Jung Ho Kang and 5, excluding any text within the (R) and SS tags. <td id="lineup-table-top"> <b class="text-muted pad-left-10">5& ...

Working with floating point numbers in Node.js with a zero decimal place

NodeJS interprets float values with a zero after the decimal point as integers, but this behavior occurs at the language level. For example: 5.0 is considered as 5 by NodeJS. In my work with APIs, it's crucial for me to be able to send float values w ...

Ways to address postcss vulnerabilities in a create-react-app generated application

Approximately one month ago, I developed a new app using create-react-app. Recently, after running npm update, I received the following message: 80 moderate severity vulnerabilities To address issues that do not require attention, run: npm audit fix To ...

Can you provide some straightforward instances of single-axis zooming using d3?

I'm interested in creating a single-axis zoom for d3's zoom behavior. Are there any straightforward examples that demonstrate how to achieve this? I came across Mike Bostock's example, but I found it a bit complex to grasp. Here is the code ...

Is the renderer.setSize in Three.js calculated as a percentage of the screen size?

Is it possible to calculate the renderer.setSize based on a percentage of the screen? For instance, could I set my frame to be 80% of the device width and 80% of the device height? ...

What is the reason behind the length property belonging to an array object?

While there are other instances, let's focus on the length property for now. Why does it appear as if we're copying it here: [].hasOwnProperty("length") //==> true It is common knowledge that an array's length property belongs ...

Saving the Structure of an XML Document Using JQuery

Xml: <Data> <Cat> <Name>Fluffy</Name> </Cat> <Cat> <Name>Willy</Name> </Cat> </Data> JQuery: // ...Executing ajax requests... $(xml).find('Cat').each(function ...

Having trouble loading a local script using NextJs "beforeInteractive" strategy

In my project using Next.js "next": "14.1.0", I have a script that needs to set some window variables as shown below: //config.js window.REACT_APP_DEPLOY_ENV = "development" window.REACT_APP_VENDOR = "some-vendor-name&qu ...

Using Webpack may require the use of specific loaders to manage certain types of files. Some loaders may struggle with loading

Struggling with my webpack configuration file as it fails to load the CSS from my imported files. After researching various similar issues online, I've updated the test regex for the loaders and included a file loader along with a URL loader, but the ...

Choosing an Option Doesn't Show Any Value (ReactJS/Material UI)

I'm having trouble creating a multi-select form control where the selected items are not getting rendered. Even though the handleChange function successfully retrieves the event.target.value, it doesn't seem to update the roleIds state. Additiona ...

The hook from Supabase is facing issues with proper importing

This project is a Spotify clone. The issue I'm facing is related to importing the hook. The error message reads: React Hook "useSupabaseClient" is called in function "useloadArtistImage" that is neither a React function component nor a custom React H ...

How can you specify the maximum width and height for a TextField in JavaFX using CSS?

Is there a way to set preferred and maximum width and height for a TextField using CSS? ...