Aligning a Material UI button to the far right of a row

I am struggling to align a React material-ui button to the right-most of the page and despite trying to use the justify="flex-end" attribute within the following code, it doesn't seem to be working:

<Grid item justify="flex-end">
      <Button              
        variant="contained"
        color="primary"
        onClick={() => myFunction()}
      >
        Submit
      </Button>
</Grid>

I attempted using justify="flex-end", however, the alignment issue persists.

Answer №1

This solution has been successful for me.

<Box display="flex" justifyContent="flex-end">
  <Button              
    variant="contained"
    color="primary"
    onClick={() => myFunction()}
  >
    Submit
  </Button>
</Box>

If you prefer to utilize Grid, consider using inline styles in this manner.

 <Grid item style={{display:"flex"}} justify="flex-end">
          <Button              
            variant="contained"
            color="primary"
            onClick={() => myFunction()}
          >
            Submit
          </Button>
</Grid>

Answer №2

In my opinion, the justify= attribute should be placed on the container rather than on the item, as shown below:

<Grid container justify="flex-end">
  <Grid item>
    <Button              
      variant="contained"
      color="primary"
      onClick={() => myFunction()}
    >
      Submit
    </Button>
  </Grid>
</Grid>

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

Working with ReactJS, Material-UI, and Javascript: Facing challenges in applying rounded borders to TableRow components

I've been trying to achieve rounded borders on a TableRow element, but adding the style "borderRadius: 5" doesn't seem to have any effect. When I try wrapping the TableRow in a Box element with borderRadius, it does make the borders rounded but m ...

What is the method to adjust the anchor point for a MUI popover?

I currently have the following code for handling a popover: const [open, setOpen] = useState(false); const anchorRef = createRef() const handleClose = () => { setOpen(false); }; const handleClick = useCallback( (event: MouseEvent<H ...

Click on the hyperlink to adjust the background size of an inline list item

I created a navigation bar using inline display for the li elements. I want my last column to have a defined height background. However, it is only displaying a background behind the name of the column. Here is the relevant section from style.css: #navi ...

Troubleshooting problem with ion-input in Ionic 3 regarding the keyboard issue

Issue with Keyboard Overlaying Button In my ionic3 app, I am facing an issue where the keyboard overlaps the "Registrarse" button when it is open, as shown in the image. The button is positioned at the bottom of the ion-content using CSS rules such as pos ...

Endless stream of text flowing in a continuous line within each paragraph

I am trying to create a unique scrolling effect for each line in a paragraph. The goal is to have each line repeat after one scroll is completed. For example: Let's say there is a line like this in the paragraph: 1,2,3,4, The desired outcome is for ...

Ways to determine if a class is a part of the bootstrap framework

Is there a way to verify if a class like mt-3 or table-left is part of the bootstrap framework? Are there any online resources, tools, or plugins in VSCode that can assist me in determining if a class is a predefined bootstrap keyword? ...

Encountering a issue when trying to render an image retrieved from an API in Next JS

I encountered an issue where I am unable to retrieve the image from the API. Strangely, it works fine with the img tag but throws an error when switching to the NextJS Image tag. import React, { useState, useEffect } from "react"; import ...

Ways to conceal the picture

Check out the JSfiddle link here for the full code. I'm having trouble with my slider as the last picture keeps collapsing underneath and is not hidden as it should be. I suspect this issue is causing the slider to malfunction. HTML <div class=" ...

Creating a customized "404 Not Found" page using React Router 4 with nested routes

Consider the following route configuration: <Switch> <Route path="/my-profile" component={MyProfile} /> <Route path="/logout" component={Logout} /> <Route component={NotFound} /> </Switch> While the 404 pag ...

New to CSS Media Queries? Discover the Correct Way to Define Element Height!

Sorry for the oversized images! I'm diving into media queries for the first time. When I adjust my browser window to 320px, here's how my site displays: This is what I want it to look like on mobile phones. However, when I view it on my iPhone, ...

Problems with CSS animations on mobile devices in WordPress

On my website powered by Elementor Pro, I have implemented custom CSS to animate the Shape Divider with a "Brush Wave" style. Below is the code snippet: .elementor-shape-bottom .elementor-shape-top .elementor-shape body { overflow-x:hidden; } @keyframes ...

An error occurs when trying to execute the "products" function after performing destruct

I designed my homepage to showcase the products using the redux method. However, I did not want to display them all on the home page at once, so I created a single product component instead. But then I decided I wanted to show the products in a carousel us ...

The Carousel feature functions properly with 3 or more slides, but malfunctions when there are only 2 slides present

After implementing a minimal carousel, I discovered that it functions perfectly with 3 or more slides. However, as soon as I remove some slides, issues start to arise. Some of the problems I encountered include: The sliding animation is removed on ' ...

Issue with Quantity Box not displaying values in Shopify store

I am currently seeking assistance with resolving an issue I have encountered on a Shopify theme that I recently customized. The problem lies within the quantity box on the live site where despite being able to adjust the quantity using the buttons, the act ...

What methods can be used to control access to document.styleSheets data, and what is the purpose behind doing so?

Recently, I came across the document.styleSheets API, which allows you to access stylesheets used by a website. Using this API is simple, for example, document.styleSheets[0].cssRules will provide all CSS rules for the first stylesheet on a page. When I t ...

Finding and identifying specific text within Paper Material-UI can be achieved through a few

I have been attempting to vertically center the text inside a Paper component from material-ui. Below is my code: const style = { height: 150, width: 150, margin: 20, textAlign: 'center', rounded: true }; render () { ...

PHP: Using conditional statements to adjust datetime formatting for CSS styling

My title may not make sense, as I am new to PHP. I'm trying to create a custom member tag for my forum that shows "X Years of Experience" with different colors based on the number of years. For example, red for under 6 months, blue for year one, yell ...

Passing Data from Child to Parent Components in ReactJS

I'm new to React and JavaScript, currently working on a website. I've encountered an issue with passing data between components from child to parent. Here's the scenario: In my App.js script, I'm using react-router-dom for routing. I ...

Maintain React state persistence across page transitions using localStorage

Within the code snippet below import Link from "next/link"; import { useState, useEffect } from "react"; export default function IndexPage() { const [toggleState, setToggleState] = useState(true); const handleClick = (destination) ...

CSS directives are not compatible with Internet Explorer 8

I implemented a registration form with CSS rules that highlight error fields with a red border when users submit incorrect or empty data. However, this functionality is not working in Internet Explorer. The red border appears correctly in Firefox and Safar ...