Step-by-step guide to implementing a floating action button on the bottom-right corner of a screen using Material-UI in a React application

I have been attempting to place the FloatingActionButton on the bottom right corner of the screen. To achieve this, I am utilizing the following library: http://www.material-ui.com/#/components/floating-action-button

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

import AppBar from "material-ui/AppBar";
import FloatingActionButton from "material-ui/FloatingActionButton";
import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
import * as strings from "./Strings";
import styles from "./Styles";
import ContentAdd from "material-ui/svg-icons/content/add";

const AppBarTest = () =>
  <AppBar
    title={strings.app_name}
    iconClassNameRight="muidocs-icon-navigation-expand-more"
  />;

class App extends Component {
  render() {
    return (
      <MuiThemeProvider>
        <div>
          <AppBarTest />
          <FloatingActionButton style={styles.fab}>
            <ContentAdd />
          </FloatingActionButton>
        </div>

      </MuiThemeProvider>
    );
  }
}

export default App;

Styles.js

const style = {
    fab: {
        backgroundColor: '#000000'
    },
};

export default style;

Question 1

The current placement of the FloatingActionButton is at the top-left side, but I desire to position it on the bottom-right side. How can I accomplish this?

Question 2

Why are styles not being applied to the FloatingActionButton?

https://i.stack.imgur.com/DbXQj.png

Answer №1

Consider implementing this design:

const fabulousStyle = {
    right: 20,
    position: 'fixed'
};

When applying additional styles like margin or top, avoid using auto with position: fixed

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

How can I determine which component the input is coming from when I have several components of the same type?

After selecting two dates and clicking submit in the daterange picker, a callback function is triggered. I have two separate daterange pickers for SIM dates and Phone dates. How can I differentiate in the callback function when the user submits dates from ...

jPlayer 2.0 Time Tracker: Know How Much Time Has Passed and How Much

Using jPlayer 2.0 for my project. The play, pause, and other functions are all working fine, but I'm struggling to retrieve the elapsed/remaining time attributes from the jquery object. I've experimented with event handlers and tried setting up ...

Designing a blurred and distinct margin with the hover effect in html and css

Hey there, I've been attempting to replicate the hover effect on the buttons located on the left-hand side of this site , but unfortunately, I haven't had much success. The effect seems to involve a shift in margin and an unevening of margins tha ...

What is the best way to update the current navigation in React with Next.js?

I have this script set up for header navigation. const navLinks = [ { title: 'Home', path: '/', active: true }, { title: 'Services', path: '/services', active: false }, { title: 'Contact', path: &apos ...

What is the best way to have react-bootstrap's Dropdown automatically open when hovering your mouse over it?

Looking for a simple solution. I want the dropdown to open when hovering over it, rather than clicking on it. Here is my current code: <Nav> <NavDropdown onMouseEnter = {()=> isOpen=true} open={isOpen} noCare ...

Issue encountered at 'site construction' phase: failure in build script with exit code 2

I am a novice and struggling to solve this error. I have attempted to fix it by adjusting the deploy settings, but I can't seem to resolve this compilation error. The syntax errors are overwhelming, and I'm not sure if there is something crucial ...

Using CSS to overlay a background image on top of a background gradient

Struggling to get both a background gradient and a background image (transparent PNG) to display in my div. No matter what, only the color gradient shows up while the image remains hidden. If I use a solid color instead of a gradient, the image displays ju ...

No feedback received after sending keys using Selenium

Whenever I execute my code using PhantomJS and Selenium, the result appears to be correct. However, when it comes to using send_keys function, the code gets stuck without any errors, answers, or progress. I am puzzled and eager to find out why this is ha ...

Error encountered in NextJS: Styles written in SASS do not take effect on AMP pages

Why are SASS styles not being applied to AMP pages, but functioning properly on normal webpages? The nextjs docs do not provide any guidance on using SASS styles for AMP pages. Do we need to configure next.config.js? import React from "react"; im ...

Change a div to scroll vertically instead of expanding to accommodate its content

I am facing an issue with the layout I have created. It consists of a scrollable list of items in the center, with additional content above and below it in a column. The challenge is to make the list occupy all available empty space within the column witho ...

The value you have assigned, `undefined`, is out of range for the select component in react material-ui

<FormControl size="small" variant="outlined" style={{ width: '100%' }} > <InputLabel>Type</InputLabel> <Select label="type" value={'' || selectValue} onChange={han ...

Hiding the overflow conceals the entire image in one direction, while leaving the other exposed

Here is the code I have written for my project (view fiddle here): img { width: 200px; height: 200px; } .image-container { width: 600px; height: 200px; overflow: hidden; } I am working with multiple images, all sized at 200px by 200p ...

Scrolling without limits - cylindrical webpage (CSS/JS)

Is it possible to create a page that infinitely scrolls from top to top without going straight back to the top, but instead showing the bottom content below after reaching it? Imagine being able to scroll up and see the bottom above the top like a 3D cylin ...

Having trouble with Material-UI Textfield losing focus after re-rendering? Need a solution?

I am currently utilizing Material-ui Textfield to display a repeatable array object: const [sections, setSections] = useState([ { Title: "Introduction", Text: "" }, { Title: "Relationship", ...

Utilize a function inside the useContext hook in React/Next

I have successfully moved the Firebase auth to a useContext component. However, I am currently facing a challenge in referencing the async GoogleLogin function from the useContext to the button's onClick event on the Login page. Here is my UserContex ...

What is the best way to adjust the font size for a bootstrap-select dropdown menu?

I attempted to create a new CSS class to customize the appearance of the dropdown menu, but unfortunately, it doesn't seem to be taking effect. #form.py class fundForm(forms.Form): fund = forms.ChoiceField(choices=FUND, required=True, widget=for ...

Instructions on how to set up npm within a specified directory

Here is the folder structure: I have a folder with npm installed, but when I copy it to my desktop and try to run it, it doesn't work. I usually use "npm run ds" to start the server and view the website. Since my desktop does not have npm installed, ...

The Validation Library known as 'Yup' encounters compilation issues with TypeScript

After deciding to utilize the Yup library for form validation in my project, I encountered a persistent and confusing library error each time I tried to install it. This issue has been plaguing me despite numerous attempts to troubleshoot. Any suggestions ...

Is there a way to remove the deleted item from the user interface when the button is clicked using react alongside redux toolkit?

I've encountered an issue while developing a blog app using React and Redux Toolkit. When trying to delete a post, it gets removed from the database, and a success message is displayed in the UI, which is pulled from MongoDB using Redux Toolkit. Howev ...

Why doesn't jQuery UI's addClass method animate visibility like it should?

One of the advantageous features of jQuery UI is its enhancement of the jQuery addClass method, which enables animation by including a second parameter for 'duration', as shown below: $('div').addClass('someclass', 1000); Th ...