(Struggles with MUI v5) Finding it challenging to position a button in the top right corner

I attempted to position a MUI button in the top right corner, but for some reason, I couldn't move the button without using margin left and right. However, this is not an ideal solution for my project.

import './NavigationPage.css'
import * as React from 'react';
import videoBg from '../assets/videos/japan_bg2kTrim.mp4'
import IconButton from '@mui/material/IconButton';

function NavigationPage() {

 const [muted, setMuted] = React.useState(true);
 const handleToggleMute = () => setMuted(current => !current);

 return (
   <div>
     <IconButton variant='contained' onClick={handleToggleMute} 
       sx={{ display: 'flex', justifyContent: 'flex-end'}}>Unmute</IconButton>
     <video src={videoBg} autoPlay loop muted={muted}/>
   </div>
 );
}

export default NavigationPage;

My CSS:

* {
  margin: 0;
  padding: 0;
  font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
}

video {
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  object-fit: cover;
  position: fixed;
  z-index: -1;
}

Does anyone have suggestions for placing the button in the corner without relying on margins?

Answer №1

Applying the style display: flex to your IconButton won't have any effect since it only creates a flex box and impacts its child elements. The property justifyContent also influences the child elements within the flex box.

To achieve the desired result, I recommend using the style position: fixed as demonstrated below:

<IconButton variant='contained' onClick={handleToggleMute} 
   sx={{ position: "fixed", top: 0, right: 0, zIndex: 2000 }}>Unmute</IconButton>

You can customize the values of top and right to adjust the margin according to your preferences.

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

The Angular overlay panel remains open consistently

I recently developed an Angular component similar to p-overlaypanel, but I'm facing an issue where it remains open for every item I click. What I actually want is for only one overlay panel to be clicked and shown at a time - if I click on another ove ...

Encountering issues with paginating remote data in Material Table React

I'm struggling with showcasing data from the rest service on a Material Table. Whenever I perform a periodic refresh, the table re-renders each time, making it impossible for the user to stay on the same page. Is there a solution to save the current p ...

Incorporating multiple CSS style sheets within a single HTML document

As part of my assignment, I have successfully created two different CSS style sheets. The next step is to link both style sheets to a single HTML page and provide users with the option to switch between the two styles. I am wondering how to achieve this. ...

Centering dilemma in the div

I have a main container with a width of 940 pixels. Inside the main container, there are two divs with a width of 250px each. My goal is to center align these boxes within the main container. However, the issue arises when the second div is added dynamic ...

Is it possible for HTML, AJAX, and PHP to work together seamlessly in synchronous harmony? Or could

After extensive research, I have managed to find a more efficient way to connect JavaScript to PHP using Ajax. My main goal was to reduce the amount of code while maintaining maximum speed. One breakthrough I made was passing AJAX a value by Object, allowi ...

Tips on confirming my input field using a specific formula

I am in the process of validating my input field within a redux form using a specific formula. This particular formula consists of 4 key terms that I want to limit users to entering exclusively. The terms are: TERM1, TERM2, TERM3, and TERM4. While constr ...

Encasing the app component with a context and encountering the issue: TypeError - (destructured parameter) does not have a defined value

My goal is to wrap all components under the app in a context to provide specific functionalities (as evidenced by my UserContext component). import React, { useState, createContext, useContext } from 'react' const Context = createContext(); exp ...

Tumblr post not automatically playing flash content

I am facing an issue with embedding a flash object on my tumblr blog (Billy's audio player) where I have to click a white play button for the object to work properly. This problem seems to occur specifically in Chrome and Edge browsers, as other websi ...

Looking to separate a string following a specific word?

Below is the code snippet provided: var url="https://muijal-ip-dev-ed.my.salesforce.com/apexpages/setup/viewApexPage.apexp?id=066415642TPaE"; The desired output from this string is: url="https://muijal-ip-dev-ed.my.salesforce.com/" We want to keep only ...

Setting margins for individual cells in a CSS table

I am looking to create a table with a left floated cell, a right floated cell, and the middle cell to remain centered. For example: https://i.sstatic.net/xXo59.png Issue: As the content within the middle cell increases, it shifts further to the left, red ...

Styling elements with pseudo-classes when a horizontal scroll bar is activated

I have been experimenting with CSS pseudo-classes, specifically the before and after classes. While I have had no issues with the before class, I am running into a horizontal scroll problem when using the after class. I want to avoid using overflow: hidde ...

how to use beautifulsoup to insert a new tag within a text block

When a browser encounters the text www.domain.com or http://domain.com/etc/ within an HTML text section, it automatically converts it into <a href="http://www.domain.com">www.domain.com</a> or <a href="http://domain.com/etc/">http://domai ...

Using jQuery to assign the value of a hidden element to data being posted

When using jQuery's post() method to call an ajax action that returns JSON data ({"Success": "true" } or {"Success": "false"}), the value of a hidden HTML element is supposed to be set to the Success value in the returned object. However, after settin ...

Press the button to update the dropdown selection and refresh the widget with the newly chosen option

I'm currently working on integrating a Healcode widget (via Mind Body) into the website project I'm handling. My main objective is to implement a button on that specific page that will modify the dropdown selection of the Healcode widget and then ...

Custom Material-UI TextField with mandatory input

Within the Component, you have the option to specify whether a field should be mandatory or not. However, I am interested in replacing the symbol * with * mandatory field. Is it possible to customize this in any way? ...

Dynamic parallax or stacked vertical text animation

I am attempting to replicate the text effect found on . The text is centered both vertically and horizontally within each div, but as you scroll down, the top position shifts creating a parallax effect. As you continue scrolling, the text transitions to th ...

Could Bootstrap CSS components be transformed into Tailwind CSS?

Incorporating the Tailwind CSS library into my current web project has been a game-changer. I am now considering the possibility of converting all of the Bootstrap CSS components to use in my project. Is this transition feasible? ...

The axios.get function is not correctly updating the state within the ComponentDidMount method

When setting up conditional rendering in my header component to display different links based on the user's login status, I encountered an issue where one set of links briefly flashes before showing the correct set. After some investigation, I realize ...

Error: The query creation was unsuccessful because phrase prefix queries can only be applied to text fields, not to the [customer_name] field with type [keyword]

When utilizing the ElastichSearch Search UI with the provided configuration: const configurationOptions = { apiConnector: connector, alwaysSearchOnInitialLoad: true, searchQuery: { search_fields: { customer_name: { } }, result ...

Leveraging an intersection type that encompasses a portion of the union

Question: I am currently facing an issue with my function prop that accepts a parameter of type TypeA | TypeB. The problem arises when I try to pass in a function that takes a parameter of type Type C & Type D, where the intersection should include al ...