When you hover the cursor over it, the material-ui icon button shines with an elliptical background effect

There seems to be a strange issue with the IconButton in @material-ui/core/IconButton that is causing a weird elliptical background to appear when hovering over it.

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

Even after copying the code directly from the material-ui website, the problem persists.

Interestingly, when I created a new React project and implemented an icon button, the background displayed as the usual circle.

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

As a newcomer to React, I am unsure of what might be causing this issue. I have not applied any explicit styling to the icon button.

App.js

import React, { Component } from 'react';
import './App.css';
import { IconButton } from '@material-ui/core';
import WorkIcon from '@material-ui/icons/Work';
import CssBaseline from '@material-ui/core/CssBaseline';

class App extends Component {

    render() {
        return (
            <div>
                <CssBaseline />
                <IconButton>
                    <WorkIcon />
                </IconButton>
            </div>
        );
    }
}

export default App;

App.css

.App {
  text-align: center;
}

.App-logo {
  animation: App-logo-spin infinite 20s linear;
  height: 80px;
}

.App-header {
  background-color: #222;
  height: 150px;
  padding: 20px;
  color: white;
}

.App-title {
  font-size: 1.5em;
}

.App-intro {
  font-size: large;
}

@keyframes App-logo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}


.MuiCardContent-root-29 {
    display: inline-block;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 500px;
    height: 300px;
    margin: auto;
    background-color: #f3f3f3;
}

.login {
    margin-top: 50px;
    margin-left: 50px;
}

.form-group {
    margin-bottom: 35px;
}

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from "react-redux";

import './index.css';
import App from './App';
import store from "./store/index";
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<Provider store={store}>
    <App />
  </Provider>, document.getElementById('root'));
registerServiceWorker();

index.css

body {
    background-color : #484848;
    margin: 0;
    padding: 0;
}
h1 {
    color : #000000;
    text-align : center;
    font-family: "SIMPSON";
}
form {
    width: 300px;
    margin: 50px auto;
}

button {
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
    opacity: 0.9;
    width: 100px;
}

.tableHeader {
    background-color: green !important;
}

.header {
    color: green;
    font-weight: bold;
}

.edit {
    height: 30px;
    cursor: pointer;
}

.delete {
    height: 20px;
    cursor: pointer;
    padding-left: 10px;
}

The issue persists throughout my entire project wherever icon buttons are used, not just within this specific file. Interestingly, using the same file in a new project results in no elliptical backgrounds.

EDIT:
The solution provided above works effectively. In my case, setting the width property of the button in index.css to auto also resolved the issue.

Answer №1

Here is the solution I implemented to get rid of the elliptical shape:

<IconButton style={{borderRadius: 0}}>
     <DeleteIcon/>
</IconButton>

After this change, the shape will now be a perfect rectangle upon hovering.

Answer №2

Hey there! If you want to customize the ripple effect on your components, you can easily override the root and child styles. You can change things like border radius or background color to suit your design needs.

const useStyles = makeStyles({
  root: {
    borderRadius: 0, // Customize icon button root style here
    '.MuiTouchRipple-ripple .MuiTouchRipple-child': {  
      borderRadius: 0, // Change ripple style when clicked or touched
      backgroundColor: 'red'
    },
  },
});
<IconButton className={classes.rippleRoot}>
  <WorkIcon />
</IconButton>

If you're using MUI5 with sx props, you can achieve the same customization:

<IconButton
  sx={{
    borderRadius: 0,
    '.MuiTouchRipple-ripple .MuiTouchRipple-child': {
      borderRadius: 0,
      backgroundColor: 'red',
    },
  }}
>
  <WorkIcon />
</IconButton>

Answer №3

After trying a couple of solutions that didn't work for me, I decided to make some adjustments in my App.css file. I added margin and width properties to the parent element, as well as a padding-right property to the child element.

//Styling for buttons at the top

    button.MuiButtonBase-root {
      margin: 10px;
      width: 50px;
    }
    
    button.MuiButtonBase-root span span {
      padding-right: 50px;
    }
    
//Styling for checkboxes

    span.MuiButtonBase-root {
      margin-left: 10px;
      width: 45px;
    }
    
    span.MuiButtonBase-root span {
      padding-right: 10px;
    }

Answer №4

To achieve a circular shade effect on hover, set the height and width to the same value.

<IconButton sx={{height: "50px", width: "50px"}}>
   <WorkIcon />
</IconButton>

Answer №5

Success with this method

<ButtonWithIcon style={{height:"45px",marginTop:"20px"}}>
    <DeleteIcon/>
</ButtonWithIcon>

Answer №6

<CustomButton style={{ borderRadius: 10 }}>
   <OfficeIcon />
</CustomButton>

Answer №7

The issue lies within the CSS for the `button` in your index.css file. It appears to be setting the width of all buttons to 100px, affecting the appearance of the `IconButton` which is implemented as a button tag around the icon.

Fixing the styling of the `IconButton` can be easily resolved by removing the specific `button` CSS. However, the challenge arises when you still want that button style applied to other buttons on your page.

To address this, one approach would be to modify the `index.css` file as follows:

.standard-button {
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
    opacity: 0.9;
    width: 100px;
}

Then, replace instances where you are rendering `button` elements with:

<button className="standard-button">

instead of just <button>.

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

Cannot see the box-shadow with :before and z-index in CSS

My main objective is to prevent the box-shadow from overlapping with adjacent elements by utilizing the :before pseudo-element and adjusting the z-index. However, I am facing an issue where the shadow appears beneath the container of the list item that is ...

The CSS file I've linked to in my HTML (ejs) document seems to be getting

As I work on developing my app from the backend, I am encountering an issue with loading CSS locally on my page. I am utilizing Node.js, Express.js, and EJS for my pages - part of the MEN/MEAN stack. <link href="../public/stylesheets/style.css" rel="st ...

Clicking the React Todo Delete Button instantly clears out all tasks on the list

I am dealing with 2 files: App.js import React, { Component } from 'react'; import './App.css'; import ToDo from './components/ToDo.js'; class App extends Component { constru ...

Resolving Conflicts in NPM Dependencies

Whenever I execute node install, the output I receive is as follows: npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e19111119121b53 ...

Personalized Salutations using AWS Amplify

After successfully wrapping my Route objects (using react-router-dom) with the Amplify withAuthenticator Higher Order Component, I have ensured that they are only accessible to logged-in users. The Amplify Login screen is displayed for those who are not lo ...

Ways to incorporate a dictionary into your website's content

I am in the process of developing a website for educational purposes while also honing my web programming skills. On this website, I have encountered some complicated terms that may be difficult for users to understand, so I want to implement a tooltip/mod ...

Transpiling JSX on the client-side

Looking to develop React applications with JSX without the need for a terminal or server-side commands? The environment we're working in doesn't support running commands, and our goal is to host these applications purely on a CDN. I've been ...

Modifying webpage code

I am looking to develop a system where I can edit various elements such as the navbar, paragraphs, and images directly from a web page. I understand that this can be achieved with JavaScript, but I am facing the issue of my customizations reverting to defa ...

What is the best way to insert a tagline above a form?

I'm struggling to figure out where to place a tagline above my form. I want it to be neat and clean, but haven't been successful in finding the right spot. I attempted to insert an <h2> inside the form, but it doesn't look good at al ...

Why don't inline style changes implemented by JavaScript function properly on mobile browsers like Chrome, Dolphin, and Android?

View the jsFiddle here Issue on PC/Windows browser: When performing action, h1 header "gif" disappears and video starts playing. Problem on mobile devices: The gif does not disappear as expected but the video still plays indicating that JavaScript is fun ...

What could be causing this code to malfunction in Internet Explorer 7?

Code: Demo: In the majority of modern browsers such as Safari, Chrome, Firefox, and IE8/9, the code works perfectly fine. However, there seems to be an issue with IE7, causing it not to work. Any idea why this might be happening? My goal is for the conte ...

What is the method for adjusting the font size of the label in an Angular mat-checkbox element?

I've been trying to adjust the font size of a mat-checkbox's label, but no matter what I do, the component's default styles keep overriding my changes: Using !important Trying ::ng-deep Applying a global style in styles.scss <mat-checkb ...

Creating inline styles within React.js

What is the proper way to include inline CSS in react.js? <div className="p-3" style={{backgroundImage: linear-gradient(to right top,#FB0712,#124FEB)}} > I am encountering an error (Error: Expected ',', got 'right') wit ...

showing the upload preview and disabling automatic uploading in Dropzone with React

Currently, when the user clicks the upload button and selects a file, it automatically uploads the file. However, I do not want this automatic upload to happen. Instead, I want to display the selected files to the user first before uploading them. I need ...

Heroku hosting a React/Node application that serves up index.html and index.js files, with a server actively running

It seems like the issue I'm facing is related to my start scripts. After researching online, I've come across various start scripts shared by different people. Some suggest using "start": "node index.js" -> (this doesn't start my server ...

When it comes to Redux-thunk, why not just call a function directly instead of dispatching it through a handler?

My understanding of redux-thunk is that it allows for: <button onClick={fn1}>Click Me</button> In the function fn1, instead of directly dispatching an action object, it dispatches another function fn2. This way, when the redux-thunk middlewar ...

The issue with the Next.js navbar is that the highlighting does not disappear when a link from a different <nav> group is clicked

Currently, I am working on setting up a navbar with active link highlighting using Next.js (and React-bootstrap). I have been following a guide on how to achieve this from this source. While some aspects of the highlighting are functioning as expected, ot ...

Why is Windows not able to recognize ". " as an internal or external command?

I have encountered an issue with the line in the package.json file. "start:setup": "./start-setup.sh", When trying to run the command npm run start:setup from the Windows command prompt, I receive the following error: '.' is not recognised as ...

The installation of dependencies for my nano-react-app is unsuccessful when using the npm install command

After running the command npx nano-react-app tictactoe to create a new app, I proceeded with npm install to ensure all dependencies are installed. Below is the content of the package.json file that accompanied the nano-react-app: "name": " ...

employing iframes dynamically to overlay a webpage

I inserted this iframe into a webpage <iframe src='http://redbug.redrocksoftware.com.au:80/Pages/chamara.html' style="position:absolute;z-index:1;" ></iframe> The chamara.html page has a button that, when clicked, should cover the c ...