Vertical alignment in material-ui's Grid component is not functioning as expected

I have been working on this code snippet to center a button both vertically and horizontally. However, it seems like the button is not positioned correctly along the vertical axis. Any advice or guidance would be greatly appreciated!

Could someone assist me in troubleshooting this issue?

import React from 'react';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';

function App() {
  return (
        <Grid container direction="row" justify="center" alignItems="center" justifyContent="center">
          <Grid item>
            <Button variant="contained" color="primary">Hello</Button>
          </Grid>
        </Grid>
  );    
} 

export default App;

Answer №1

Check out this code snippet.

import React from "react";
import Button from "@material-ui/core/Button";
import Grid from "@material-ui/core/Grid";

function App() {
  return (
    <Grid
      container
      spacing={0}
      direction="column"
      alignItems="center"
      justify="center"
      style={{ minHeight: "100vh" }}
    >
      <Grid item>
        <Button variant="contained" color="primary">
          Hello
        </Button>
      </Grid>
    </Grid>
  );
}

export default App;

https://codesandbox.io/s/great-nash-8o2ke

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

A guide to resolving the Prisma Unique Type error while deploying on Vercel

After successfully running the app in my local development environment, I encountered an unexpected type error upon deploying to Vercel. My tech stack includes Next.js, Prisma, and tRPC. Any suggestions on what could be causing this issue? Link to Code ...

Perform validation on input by monitoring checkbox changes in Angular 4

I am currently working on a project where I need to loop through an array of key values in order to create a list of checkboxes, each accompanied by a disabled input field as a sibling. The requirement is that upon checking a checkbox, the corresponding in ...

The React project encountered a build failure following the execution of the npm run command, resulting in the error code ELIFCY

I encountered an error while attempting to run my React project on localhost. Is there anyone who can provide assistance? Here is the error log: C:\Users\Intel\Desktop\burger-project>npm start > <a href="/cdn-cgi/l/email-prote ...

`I'm having trouble displaying text within a div element`

I am diving into the world of React.js for the first time with my new project. I followed the steps outlined in this tutorial to create a simple Hello World application (https://facebook.github.io/react/docs/hello-world.html) Despite importing React.js in ...

Reset the chosen option and clear the displayed list

When utilizing the React-Select library to create a selector for the onChange event, I encounter an issue where the selected city remains when changing the region. Even though the list of cities updates after changing the state, the selected city does not ...

Personalizing label formatting for a RadioGroup component in React

I am currently utilizing the material-ui RadioGroup component with dynamically assigned individual labels. The width is set to '50px' in the parent component. However, the issue arises when a label exceeds the 50px width, causing the entire compo ...

Insert an element into a JSON collection

I am currently working on a JavaScript function that utilizes an ajax call to retrieve data from an API in the form of a JSON array. Here is a snippet of the array structure that I receive: [ { "ErrorType": "Errors", "Explanations": [ { ...

Issue with deploying Digital Ocean app: npm ci is not running due to package and package-lock being out of sync

Recently, I've been encountering a fatal error while trying to deploy my app on Digital Ocean. The error message reads: [2022-06-13 07:11:31] npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap ...

ReactJS: Error - ReferenceError: React is not defined (no-undef)

I recently started learning React by following the tutorial on reactjs.org. After setting up my project using npm and creating my index.js file, I encountered an error: src\App.js Line 9:21: 'React' is not defined no-undef Line 42: ...

The functionality of getAttribute has changed in Firefox 3.5 and IE8, no longer behaving as it did before

Creating a JavaScript function to locate an anchor in a page (specifically with, not an id) and then going through its parent elements until finding one that contains a specified class. The code below works perfectly in Firefox 3.0 but encounters issues wi ...

Exploring the Differences Between Meteor JS Backend and Express JS

I have a basic understanding, but I'm interested in learning more: I came across a comparison on Stack Overflow that likened Meteor JS and Express JS to oranges and potatoes. My current understanding is that Meteor JS is full stack (Front End, Back E ...

The concept of nested views in Angular UI-Router allows for a

How can I successfully implement nested views, where after logging in the user is redirected to in.html, and all links within in.html are directed to a ui-view? Currently, all links redirect to a new page. index.html <!-- more HTML --> <body ng- ...

Having trouble closing the phonegap application using the Back Button on an Android device

I've encountered an issue with my code for exiting the application. It works perfectly the first time, but if I navigate to other screens and then return to the screen where I want to close the app, it doesn't work. <script type="text/javascr ...

Obtaining a compressed file via a specified route in an express API and react interface

Feeling completely bewildered at this point. I've had some wins and losses, but can't seem to get this to work. Essentially, I'm creating a zip file stored in a folder structure based on uploadRequestIds - all good so far. Still new to Node, ...

Getting dynamic props from a clicked element in React involves accessing the target element's properties and

I am currently working with a React "tree" menu component that has main links with submenus generated dynamically through a JSON GET call. Upon inspecting the tree in the React Inspector, I noticed that each element has multiple props associated with it. H ...

Troubleshooting: Issue with Displaying $Http JSON Response in AngularJS View

Struggling to retrieve JSON data from an API and display it in a view using AngularJS. Although I am able to fetch the data correctly, I am facing difficulties in showing it in the view. Whenever I try to access the object's data, I constantly receive ...

Using Angular: connecting $viewContentLoaded to manually initiate app bootstrapping

I have an Angular module that I am bootstrapping manually and attempting to access its $rootScope to add an event listener for $viewContentLoaded. Below is the code snippet: angular.bootstrap(el, [appname]); //////////////////////////// Fixing links cons ...

What could be causing this JavaScript code to run sluggishly in Internet Explorer despite its simple task of modifying a select list?

I am currently developing a multi-select list feature where users can select items and then rearrange them within the list by clicking either an "Up" or "Down" button. Below is a basic example I have created: <html> <head> <tit ...

Tips for concealing validation errors in React Js when modifying the input field

I have recently started working with ReactJs, and I've implemented form validation using react-hook-form. After submitting the form, the errors are displayed correctly. However, the issue arises when I try to update the input fields as the error messa ...

Exploring Non Blocking IO through an Example

While browsing through a node.js tutorial, I stumbled upon this informative page that uses the example of a "Restaurant service" to explain a scenario. In the context of Blocking IO, they provide the following code snippet: // requesting drinks for table ...