MUI Grid - justify content to the right

I'm new to utilizing the MUI Grid system and I am currently trying to accomplish a simple task of aligning my 'Cancel' and 'Save' buttons all the way to the right on the screen. Despite browsing through various posts and documentation related to Flexbox/MUI, I have not been able to find a solution. The process seems straightforward according to the docs, but it is not impacting the layout of my page. I have experimented with alignItems, alignContent, justifyContent, etc. in an attempt to make it work, but without success.

<Grid container xs={12} justify-content='flex-end'>
    <Grid item xs={6}/>
    <Grid item xs={3}>
        <button 
            onClick={() => doSomething()}
            Click here to cancel
        </button>
    </Grid>
    <Grid item xs={3}>
        <button 
            onClick={() => doSomething()}
            Click here to Save
        </button>
    </Grid>
</Grid>

Answer №1

In case you are utilizing the Material-UI styled component, consider incorporating the styles definition provided below:

.customClass {
  display: flex;
  flex-direction: row;
  justify-content: end;
  align-items: flex-end;
}

Answer №2

There appears to be a typo with justify-content='flex-end', it should actually be

justifyContent="flex-end"
:

<Grid spacing={2} container xs={12} justifyContent="flex-end">
      <Grid item xs={3}>
        <Item>xs=3</Item>
      </Grid>
      <Grid item xs={3}>
        <Item>xs=3</Item>
      </Grid>
    </Grid>

See working example

If you want to align items along just one horizontal direction, consider using Stack instead of Grid. Stack is specifically designed for aligning items along the vertical or horizontal axis without creating redundant DOM elements (grid-item containers) in these cases:

<Stack direction="row" spacing={2} justifyContent="flex-end">
          <Item>Item 1</Item>
          <Item>Item 2</Item>
          <Item>Item 3</Item>
        </Stack>

You can view the UI example generated by this snippet at the provided link.

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

Adding flair to a fresh element and then removing it upon its inception

I'm working with a JavaScript code that creates a new element when a button is clicked. I have a question about it. Here's the JavaScript code snippet: var comment = document.querySelector("#AddComment"); var req = new XMLHttpRequest(); if(comm ...

What is the best way to retrieve a style property from a <style> tag using JavaScript?

Is there a way to retrieve CSS properties set in the <style> tag in JavaScript, rather than just those set in the element's style attribute? For example: <style> div{background:red;} </style> How can I access these styles, such ...

Creating a stylish CSS shadow effect for a collection of elements

In my Ionic2 project, I have an <ion-list> consisting of various items. Currently, these items are plain, but I desire to add some styling such that each item in the list displays a subtle shadow effect, similar to the one shown in the first image of ...

Is there a way to implement the border-box property for Internet Explorer versions 6 and

Similar Question: How to implement box-sizing in IE7 Anyone know a method or workaround to apply box-sizing:border-box; in IE6 and IE7? Even just for IE7? ...

Issue with JavaScript causing circles to form around a parent div

I am struggling to position a set of circles around a parent div in my code. I want 6 circles to form a circle around the parent div, but they are not lining up correctly. Can someone help me identify what I'm doing wrong? var div = 360 / 6; var ra ...

The issue of duplicate CSS arising during the compilation of SASS into a single CSS file with G

Just getting started with Stack Overflow and Gulp (using version 3.9.1). My goal is to compile all of my scss files into a single css file for my website. Here's what I have in my gulpfile so far: var gulp = require('gulp'); var sass = requ ...

Make sure that the input field and label are aligned side by side in the

Is there a way to arrange the following HTML in the specified layout? <div> <div> <label>Counterparty</label> <input id="paymentsApp-inpt-cpty" ng-model="selectedPaymentCopy.counterparty" ng-required="true" ...

Is it possible to have two MUI AppBars on the same page, one as the header and the other as the footer? And how can we customize their styles using createTheme()?

Is it a good idea to have two appBars components on the same page, one as a header and the other as a footer? Additionally, I am utilizing MUI createTheme to customize some styles. Specifically, I am using it to override the appBar component. components: { ...

Code snippets to reduce excess white space on a website using HTML and CSS

On my website, there are multiple tabs, each containing content from an HTML file. When a user clicks on Tab1, boxes with images are displayed. The layout can be seen in the following Code Demo: Code Demo here There seems to be extra space before and afte ...

What is the best method for incorporating a unique style to a v-dialog component in Vuetify following the most recent update?

I'm currently working on a project using vuetify, and I am facing an issue while trying to add a custom class to a v-dialog component. I have tried searching for information on how to do this, but it seems that the prop "content-class" has been deprec ...

Theme customization in Material UI includes the addition of a custom color. However, this custom color is missing from the control values in Story

Currently in my project, I am utilizing a stack that includes React 18, TypeScript, MUI 5, and Storybook 6.5. I have been attempting to incorporate custom colors into my MUI Theme and have them reflect in Storybook's dropdown options for the color p ...

Positioning images within a relatively positioned div using absolute positioning

I have come across multiple discussions on this topic, but I am still struggling to make the following code snippet function correctly: .container { position: relative; width: 100%; } .left { position: absolute; left: 0px; } .right { positio ...

Removing the active class from a Bootstrap menu can be achieved by targeting the specific

I have successfully implemented a Bootstrap Menu by placing it in a separate header.html file and using the php include function to call that file on every page of my website. However, I am now trying to figure out how to dynamically change the active cl ...

What is the process for placing a component on the right side of the sidebar?

Here is the code snippet I am working with: <template> <div class="main"> <sidebar /> <router-view /> </div> </template> The sidebar has a width of 260px. I need to ensure that any comp ...

What is the process of incorporating a 'theme' generated with 'createMuiTheme()' into 'makeStyles()'?

After creating a customTheme with createMuiTheme() and implementing it within the <ThemeProvider>, the challenge arose when attempting to apply custom styles using that customTheme in the makeStyles() function. Unfortunately, despite efforts, makeSty ...

What is the process of importing a cascading style sheet into a C# object?

Currently, I am working on a web application and I would like to provide users with the flexibility to change the styling elements of CSS linked to a page through an admin screen. I have been exploring ways to load a CSS file into a C# object or convert ...

CSS division nested within the center float division

In my attempt to design a 3-column home layout, I have successfully styled the center, left, and right sections. However, I am facing difficulty in placing two sliders within the middle class. My goal is to have slider1 positioned on top inside the middle ...

Creating a responsive card design with Material UI

Creating a responsive card layout for mobile applications is my current challenge const styles = { edit: { width: "40%", marginLeft: 270, background: "#76ff03" }, add: { width: "100%", background: "#18ffff", size: "large" ...

MUI Autocomplete, the renderInput prop: Can you explain what exactly the params are used for in this context

I'm currently in the process of familiarizing myself with MUI's Autocomplete component, and I'm encountering some confusion around the renderInput prop. I understand that its purpose is to define how the component should be displayed, but th ...

"Varying hues on various displays: Exploring RGB values and CSS for video color

Recently, I designed a webpage with a background-color of #f4afac. The video embedded in this page also features the same background color throughout, creating a seamless blend with no visible edges. On one screen, the colors appear perfectly consistent. ...