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

Reactjs, encountering a hitch in utilizing material UI: Incompatible hook call detected

As a newcomer to React, I decided to incorporate Material UI components into my project. After installing the components locally using npm install and importing them into my project, I encountered an error when trying to run start: Error: Invalid hook call ...

The resulting line will consist of the discovered string

Let's say there's an interesting HTML document presented below with associated line numbers: 30 - <div id="myDiv"> 31 - <span class="mySpan">Some Text</span> In this scenario, PHP is being utilized for a specific purpose: $ ...

Issues arise when utilizing special characters in Shopify GraphQL queries, leading to the failure of returning results

I have a query to retrieve products based on their tag category. When searching for the cd category: products(first:10, query:"tags:category:cd") { edges {} } I am able to get results with this query. However, when I search for the Yläosat ...

The HTML form is not displaying any content and instead is returning "Not a Number

I've been struggling to create a form that can generate a numerical value based on the input from two fields. Specifically, I need to calculate the output by subtracting the product of two values - one entered in an input field and another selected vi ...

Dependency management in ReactJS components

I am grappling with the optimal structure for a React component that is composed of other components. Let's look at the first example: <ColorSelect id="color" label={this.state.selectLabel} trigger={{ color: "lime", text: "Lime"}} onPropagateCli ...

What is the best way to adjust a Material UI table cell so that the text inside it spans two lines instead of just one?

Looking to enhance the native Material UI cell to display two lines of text with ellipsis instead of just one. Unfortunately, adding divs inside the cell and applying styles won't work due to the current implementation of the table. This is the curre ...

Problem with the content-editable attribute

My goal is to make each div with the class .edit editable by adding the contenteditable property: $(document).ready(function() { $(".edit").attr("contenteditable", "true"); }); However, after applying this, I found that clicking on a div with content ...

What is the best way to utilize MUI breakpoints for displaying images based on different screen sizes?

I need help displaying an image based on the screen size using MUI breakpoints. I'm struggling to understand how to implement this with MUI. Can someone assist me with the breakpoints? interface EmptyStateProps { title: string; description: string ...

How to center an image vertically inside a link using CSS

My goal is to vertically align an image inside an anchor element using the following code: <ul class="thumbnails"> <li class="span2"> <a href="#" class="thumbnail"> <img src="http://www.forodefotos.com/attachme ...

Scripting method to transfer multiple subdirectories using a cpanel.yml file (excluding the use of the wildcard)

I have been referring to the documentation found at My current issue is that when I try to copy my subfolders, it doesn't work properly unless I use a workaround. The only way I am able to achieve the desired outcome is by utilizing the following co ...

React: Import default export as a string

Help needed with JSON data import import dataOption1 from './Option1.json' import dataOption2 from './Option2.json' async setParamsByDomain(optionUser) { await this.setState({ jsonName: "data"+ optionUser}); console.log(t ...

Toggling javascript functionality based on media queries

On one of my slides, I want to display images that are specific to different devices like iPhone, iPad, and desktop. I am looking for a way to filter these images based on the device. Using display:none won't work as it's JavaScript, but here is ...

Utilizing web components in React by solely relying on a CDN for integration

I have a client who has provided us with a vast library of UI elements that they want incorporated into our project. These elements are stored in javascript and css files on a CDN, and unfortunately I do not have access to the source code. All I have at my ...

The passing of NODE_ENV from ECS Fargate to the React Application seems to be unsuccessful

I recently completed building a React application using Create-React-App. As part of the deployment process, I configured GitHub Actions to trigger a Docker Build and upload the build to AWS whenever I commit to the 'pre-production' branch. Belo ...

Use percentages for the width in CSS and pixels for the height, ensuring that both dimensions are equal

I'm attempting to create a square that adjusts its size according to the screen size. Currently, I have the width set to 25%. Is there a way to ensure that the height remains the same length in pixels as the width? Appreciate any assistance on this ...

Unable to pinpoint the source of the excess spacing within a form field

There appears to be some extra space in the text field of my form, extending beyond the container margin. Please refer to the image and JSFiddle http://jsfiddle.net/GRFX4/. Any thoughts on what might be causing this issue? Thank you. HTML: <div id="co ...

Transform Image on Hover in ReactJS

I am working on a Card Component that includes an image and text. Initially, the image is redImage and the text is black. When hovering over the card, I want the redimage to change to whiteimage and the text color to change to white as well. The content ...

Adjust the color of the IconButton

I am trying to customize the color of an IconButton by setting it to red <IconButton variant='contained'> <StarBorderRoundedIcon color='red' /> </IconButton> However, when I try this, the red color ...

Bracket notation accessor cannot be utilized with React aliases

Can someone help me figure out how to create a tabbed-page using the alias feature? I've noticed that JSX doesn't allow object bracket-accessors. Is there an alternative method I could use, considering that the dot-notation would render the alias ...

Align list items in the center horizontally regardless of the width

I have created this container element: export const Container = styled.section<ContainerProps>` display: flex; justify-content: center; `; The current setup is vertically centering three list items within the container. However, I am now looking ...