Tips for aligning a Material UI FAB button in the center and keeping it in the center while resizing the window

Is there a way to center a MaterialUI FAB button and keep it centered while resizing the window? The current positioning is not centered, as seen in the screenshot below, and it does not adjust with window size changes.

Below is the code for the current FAB button component. It is a child component and the parent component is also included.

I have tried using "justifyContent: center" but it doesn't seem to work as expected.

If anyone has suggestions on how to center the button and make it scale with window size, I would appreciate the help! Thanks!

FAB button child component

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Fab from '@material-ui/core/Fab';
import NavigationIcon from '@material-ui/icons/Navigation';
import { navigate } from "@reach/router";

const useStyles = makeStyles((theme) => ({
  root: {
    '& > *': {
        position: 'fixed',
        bottom: "5vh",
        right: "50vw",
        backgroundColor: 'green',
        width: "20vw"
    },
  },
  fab:{
    // fontSize: "35px"
  },
  extendedIcon: {
    marginRight: theme.spacing(1),
    // fontSize: "35px"
  },
}));

export default function AddListingIcon() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <Fab color="green" aria-label="add" size="large" variant="extended" className={classes.fab} >
        <NavigationIcon onClick={() => {
              navigate("/ChooseACategory")}} className={classes.extendedIcon}/>
              Get Started!
      </Fab>
    </div>
  )
}

Parent component which contains the FAB button child component

import React from "react";
import ReactNavbar from "../components/Navbar";
import Intro from "../components/Intro";
import GetStartedIcon from "../components/GetStartedIcon"

export default function GetStarted({ setSignedIn }) {
  return (
    <div>
      <ReactNavbar setSignedIn={setSignedIn} />
      <Intro />
      <GetStartedIcon/>
    </div>
  );
}

Answer №1

Your code is functioning perfectly as you originally intended. The alignment of the right side of your button appears to be centered as expected.

To enhance the layout, consider encapsulating the Button within a Flexbox. You can achieve this using the MUI Grid component with specific styling such as width:'100%', position:fixed, and utilizing the prop justify="center".

For reference, here is a jsfiddle showcasing how to implement this with plain css: https://jsfiddle.net/rq6kvw12/

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

Discover the Magic of Jquery Hover Effect Unleashed

$('.outerBox').hover( function() { $(this) > $('.innerBox').stop(); $(this) > $('.innerBox').slideDown(750); }, function() { $(this) > $('.innerBox').stop(); $(this) > $(&apos ...

Error: The function _this[("render" + data.type)] is not defined as a valid function

https://i.stack.imgur.com/Y5Dz5.jpg I encountered an error in the console that I can't seem to figure out. Despite following the Syncfusion library's documentation, the error persists. Here is the code snippet that I implemented: import React f ...

The Vite project fails to open when I attempt to run the command "npm run dev" in react

When attempting to start a new React project using Vite React, I encountered an error after running npm install and npm run dev. The specific error message is as follows: node:internal/modules/cjs/loader:1327 return process.dlopen(module, path.toNamespace ...

Tips for creating uniform image sizes within the Next Image component

Check out my NextJS app on CodeSandbox here. In this project, I am using Tailwind CSS for styling and rendering a list of products. Each product is displayed in a card with an image. I am utilizing the NextJS Image component for image rendering, but I am f ...

Is there a way for me to manage the appearance of the printed document's layout?

I have successfully added 3 print buttons to my website, each one designed to print a specific portion (div) of the webpage. Here is the code snippet for this functionality: function printPage(id) { var html="<html>"; //html+="<link rel="st ...

Guide to Re-rendering a component inside the +layout.svelte

Can you provide guidance on how to update a component in +layout.svelte whenever the userType changes? I would like to toggle between a login and logout state in my navbar, where the state is dependent on currentUserType. I have a store for currentUserTyp ...

The functionality of Next.js dynamic routes is compromised once deployed

I recently completed a website using Next.js with the following folder structure: pages |- [path] | |- index.js | |- [for-students] | |- [path] | | |- index.js | | index.js | events.js During development, everything functioned smoothly. I utilized ...

Having trouble with Viewport CSS being restricted by Blogger?

I've been working on configuring my personal blog, which is hosted on Blogger, to properly adapt to the Windows 8 IE snap feature. Through my research online, it has been suggested that I include a @viewport in the CSS. However, it seems like the CSS ...

Switch the visibility of a div tag using Next.js

Script export default function Navigation(){ let displayMenu = false; function toggleMenu() { displayMenu = !displayMenu; } return ( <> <button onClick={toggleMenu}>Toggle Navigation</button> {/*This code sh ...

Concerns arise regarding the implementation of an image slider using HTML and CSS

Hey guys, I've created an image slider, but I'm facing an issue where the first click doesn't trigger a smooth animation. Instead, it jumps to the target without any transition. I want a seamless change of images, but right now it's jus ...

Should scripts be replayed and styles be refreshed after every route change in single page applications (SPA's)? (Vue / React / Angular)

In the process of creating a scripts and styles manager for a WordPress-based single page application, I initially believed that simply loading missing scripts on each route change would suffice. However, I now understand that certain scripts need to be ex ...

Tips for refraining from transmitting visuals to cell phones in a more meaningful way

Typically when working on responsive or mobile-first design, media queries are utilized to deliver different CSS styles based on screen size. An optimal design strategy may involve not including any images in the default (small) resolution layout. While ...

Text centered over an animated underline using CSS

Seeking help with my bootstrap 4 nav menu. I have implemented a CSS animation that creates an outward underline effect for the nav-link items. However, I am struggling to center the text above the line. Any suggestions on how to achieve this? I attempted ...

A step-by-step guide on incorporating RAW css into your Jekyll website

I am experiencing an issue with loading a CSS file on my website. <link rel="stylesheet" href="/assets/css/my_file.css"> This file is located at _assets/css/my_file.css. However, when I try to load the page, the CSS file does no ...

Is it achievable to animate dynamic height using CSS? Open to JS alternatives as well

I am currently utilizing AngularJS, which enables me to utilize ng-show and ng-hide in order to display or hide elements based on a logical condition. My goal is to animate the size changes of the container when the child objects are shown or hidden, creat ...

Angular's browser animation feature allows for smooth slide-up animations from the bottom

I have been experimenting with creating a simple animation, and it's working, but in the opposite direction of what I intended. I want the div to open from bottom to top and close from top to bottom. Here is my animation code in Angular: animations: ...

Can a function be embedded within a React render method that includes a conditional statement to update the state using setState()?

My application randomly selects three values from an array found within defaultProps and then displays these values inside div elements in the return JSX. It also assigns these values to properties in the state object. I am facing a challenge where I need ...

Background cutting off right side of HTML website

While updating my supervisor's university website, I noticed a problem with the responsiveness. When resizing the browser window, a horizontal scroll bar would appear and the right side of the website would get covered by the background. On mobile dev ...

What are the steps to increase the size of the v-stepper-step in Vuetify?

Is there a way to adjust the size of the icon/step circle in v-stepper? ...

Combining Multiple Routes with Redirect using React Router

If I have an authentication token and a function called checkToken, how can I efficiently reroute from multiple routes using React Router to avoid repetition like the example below? <Route exact path="/" render={() => { return checkToken() ? (< ...