Utilize Flexbox and Material UI to position Item at the bottom of the layout

I'm attempting to include Unassigned Text at the bottom of my Container, following the layout shown in this mockup:https://i.sstatic.net/863cl.png

Here is the code I currently have. I'm facing difficulty in getting the border between the play button to work properly. I've tried using the common css properties: bottom:0 and position:relevant as well as Flexbox, but it's not positioning itself at the very bottom of the container.

 const styles = theme => ({
  root: {
    flexGrow: 1,
    overflow: 'hidden',
    padding: theme.spacing(0, 3),
  },
  paper: {
    maxWidth: 800,
    margin: `${theme.spacing(2)}px auto`,
    padding: theme.spacing(2),
  },
  textField: {
    marginLeft: theme.spacing(1),
    marginRight: theme.spacing(1),
    width: 200,
  },
  playButton: {
    display: "flex",
    flexDirection: "column",
    justifyContent: "center",
    alignItems: "center",
    position: "relative",
    "& .playButton": {
      position: "absolute",
      top: "60%",
      left: "-55px",
      transform: "translateY(-50%)",
    },
      "& .star-rating": {
        "& .fa-star": {
          "&:hover": {
            "&::before": {
              content: "\f005",
              color: "yellow"
            }
          }
        }
      },
    },
});

function Tasks(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <Paper className={classes.paper}>
        <Grid container spacing={2}>
          <Grid item xs={12} sm container>
            <Grid item xs container direction="column" spacing={2}>
              <Grid item xs>
              <div className="name-label">
              Name
              </div>
              <Typography variant="h6" gutterBottom>
              {props.name}
              </Typography>
              <div className="form-divider"></div>
                <Typography variant="body2" color="textSecondary">
                {props.description}
                </Typography>
              </Grid>
            </Grid>
            <Grid item classes={{ root: props.classes.playButton}}>
    <Grid item xs={3} className="playButton">
      <i class="far fa-play-circle fa-2x"></i>
    </Grid>
    <div className="workers-assigned-label">
      Workers Assigned
    </div>
    <Typography variant="h6" gutterBottom>
        0/25
      </Typography>
      <div class="star-rating">
        <label class="far fa-star fa-2x"></label>
        <label class="far fa-star fa-2x"></label>
        <label class="far fa-star fa-2x"></label>
      </div>
    <div className="dropdown-menu">
  <h5>Unnassigned</h5>
</div>
  </Grid>
          </Grid>
        </Grid>
      </Paper>
    </div>
  );
}

export default withStyles(styles)(Tasks);

Any suggestions or feedback would be much appreciated.

Answer №1

If you're looking to kickstart your layout design, I suggest beginning with a Grid 'skeleton' structured like this:

<Grid container>
  <Grid item container xs={8} direction="column" justify="flex-start">
    // Content for the left column, with each row as a <Grid item>
  </Grid>
  <Fab className={classes.fab}><PlayIcon /><Fab>
  <Grid item container xs={4} direction="column" justify="space-between" className={classes.right}>
    // Content for the right column, with each row as a <Grid item>
  </Grid>
</Grid>

Using direction=column ensures vertical positioning within each container, and justify=space-between places the first item at the top and the last item (unassigned text) at the bottom.

The "right" css class has the following styling:

right: {
  borderLeft: `1px solid ${theme.palette.grey[500]}`,
  position: "relative"
}

Setting the position to "relative" makes it easier to position the fab relative to the column. The "fab" class includes the following styles:

fab: {
  position: "absolute",
  margin: "auto",
  top: 0,
  bottom: 0,
  left: -28
}

These properties help center the fab vertically, and the left property is adjusted based on the fab's dimensions to center it over the border.

For a comprehensive demonstration, check out this live example that brings everything together: https://codesandbox.io/s/tender-torvalds-dlbke?fontsize=14

Answer №2

If you're looking to achieve a similar effect, consider assigning flex: 1 to elements in the column to allow for stretching.

const styles = theme => ({
  playButton: {
    '& .dropdown-menu': {
      marginTop: "auto"
    }
  }
})

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 could be causing this error to occur in my JavaScript React code?

ERROR - '}' expected. Parse error. I'm experiencing issues with this code snippet where I try to fetch data for a graph using React, but I keep getting the parse error mentioned above. vehiculoPorColores = () => { const _this = this fet ...

Adjust scrollbar thumb size using CSS

I am looking to customize my scrollbar with a larger thumb size compared to the track. While I can adjust the color and other properties easily, I am struggling to change the sizes of the thumb and track separately. .custom_scrollbar::-webkit-scrollbar { ...

Modify CSS class if user is using Internet Explorer version 10 or above

I am attempting to modify the CSS of 2 ASP controls using jQuery specifically for users accessing the site with Internet Explorer 10 or 11. This adjustment is necessary because IE10 onwards, conditional comments are no longer supported. My approach to achi ...

The fancybox scroll feature is visible when using a browser, but unfortunately, it does not appear on the

I noticed that the scrollbar in my fancybox is not showing up on iPad, but it does display when using Google Chrome on Desktop. You can find the page here. The issue seems to be with the vertical scroll bar not appearing on iPad. Has anyone encountered th ...

Error encountered when referencing prop on textarea: 'There is no suitable overload for this call'

I've been referring to the documentation in order to set a reference using the useRef hook, with the goal of being able to programmatically clear an input field. However, when I add ref as a prop to a textarea, it triggers a lint error saying that no ...

Adding a notification button with Badge to the AppBar in Material-UI/React: A step-by-step guide

Having some difficulties with material-ui and react/jsx, I am trying to incorporate a notifications menu icon with a badge displaying the number of new notifications onto an AppBar. The issue I am facing is that the badge appears with weird styles and doe ...

Hovering over an element and eliminating any extra space

Hey there, I'm looking for some assistance with removing the whitespace on hover. Below is the code along with a screenshot for reference: div.show_sizes_onhover { background: rgba(255,255,255,.9); bottom: -1px; color: #a1a1a1; left: 0; padding: 5px ...

How about mixing up your backgrounds with an overlay effect for a unique look?

Hey there, I'm currently working on adding random backgrounds to my website through an overlay, but I've hit a roadblock when it comes to displaying them. Here is the code I'm working with: .css / .php #intro { background: ...

Detecting When a User Reaches the Bottom of the Screen in REACTjs

My goal is to monitor when the user reaches the bottom of the screen and then trigger a function to load more data. Within my app.js file, I have a Products component that handles the data fetching. The Products component is enclosed in a div with a class ...

Transformation effect when hovering over an SVG polygon as it transitions between two states

const createTransitionEffect = (navLI, startCoord, endCoord) => { const changeRate = 0.1; let currentY = startCoord; const animateChange = () => { if (currentY !== endCoord) { currentY += (endCoord - startCoord) * cha ...

Change the view using React before scrolling to a specific element on the page

How can I create a link from one view to another and scroll to a specific element without any animations? The transition between views is through react router. Is it possible to pass references to elements for scrolling, or is there a better approach? Be ...

In Next.js, a peculiar issue arises when getServerSideProps receives a query stringified object that appears as "[Object object]"

Summary: query: { token: '[object Object]' }, params: { token: '[object Object]' } The folder structure of my pages is as follows: +---catalog | | index.tsx | | products.tsx | | | \---[slug] | index.tsx | ...

Notifying a Child Component in React When a Props-Using Function Resolves a REST Call

When I submit an item or problem, I trigger a function in the parent component that has been passed down to the child component as props. After sending my information, I want to clear the input fields. The issue is that I am clearing the input fields immed ...

Exploring Chakra UI: Constructing a Dynamic Page Shell with Sidebar Navigation

I'm currently exploring how to implement the Chakra UI page shell in order to integrate components that will be displayed in the main section of each sidebar menu item. The NavButton items within the sidebar menu are structured as follows: <NavBut ...

Exploring the integration of foreign languages within C# code?

In search of a C# expert who can assist me with a question I've been struggling to find an answer for all day. Google searches have yielded outdated information, and I need fresh insight. Wondering if there's a way to incorporate CSS and HTML in ...

Managing User Information in a Next.js Application using Clerk and MongoDB

Exploring the world of Next.js and diving deep into its application architecture has been an exciting journey. With Clerk and MongoDB in the mix, I find myself pondering some important questions: User Data Management: In my Next.js 14 project powered by ...

Using SCSS based on the browser language in Angular: A Step-by-Step Guide

Is there a way to implement SCSS that is dependent on the user's browser language? When I checked, I found the browser language specified in <html lang = "de"> and in the CSS code as html[Attributes Style] {-webkit-locale: "en&quo ...

disable border-collapse styling in ASP.NET DataList

Currently, I am new to the world of ASP.NET and I am facing a challenge in styling a DataList. Lately, I have developed a fondness for rounded corners on borders, and I am attempting to incorporate this effect into all my pages by implementing it across al ...

Break up a list into separate paragraphs and style each word using individual CSS

I have a user-generated paragraph that consists of a list of words separated by commas, such as "dog, cat, hamster, turtle." I want to be able to individually assign attributes to each word in the list. Check out this image for reference In the example i ...

Fake AxiosInstance. In need of obtaining response in a single test

In my api.ts file import axios from 'axios' export const api = axios.create({ baseURL: 'http://localhost:3333/', }) Within my react-page.spec.tsx file: import React from 'react' import '@testing-library/jest-dom&apo ...