What is the best way to center the startIcon material ui icon?

I'm having trouble keeping the icon button centered on my page. When I add left: "0.5rem" to the sx prop, it ends up pushing the button icon even further away from center. I'd prefer not to use makeStyles to manually override the position. Any advice or suggestions would be greatly appreciated :)

Check out the sandbox link for reference

Answer №1

If you'd like to incorporate this into your theme, follow these steps to streamline the process and eliminate the need to repeat it for each Button component.

const customizedTheme = createTheme({
  ...
  components: {
    MuiButton: {
      styleOverrides: {
        startIcon: {
          margin: '0'
        },
      },
    }
  },
});

Answer №2

If you're looking to experiment with a new style, consider the following:

<CustomLayout direction="row" design={{display:"flex", justifyContent:"center", alignItems:"center"}}>
  <Tooltip title="Delete">
    <Button sx={{ minWidth: 0 }} startIcon={<DeleteIcon />} />
  </Tooltip>
  <Divider orientation="vertical" flexItem />
  <Tooltip title="Send">
    <Button sx={{ minWidth: 0 }} startIcon={<SendIcon />} />
  </Tooltip>
  <Tooltip title="Headset">
    <Button sx={{ minWidth: 0 }} startIcon={<HeadsetMicOutlined />} />
  </Tooltip>
  <Divider orientation="vertical" flexItem />
</CustomLayout>

Answer №3

Customize your styles

elements: {
    CustomButton: {
      customStyles: {
        startIcon: ({ userTheme }) => ({
          ...(userTheme.children
            ? {}
            : {
                // center icon when no label is present (e.g for mobile)
                marginRight: 0,
              }),
        }),
      },
    },

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

Unable to retrieve JSON element in ReactJS

Here is the code snippet that I am currently working with: const [questions, setQuestions] = useState([]) useEffect(() => { let idVar = localStorage.getItem('idVarianta'); idVar = JSON.parse(idVar) axios({ ...

Tips for adjusting the button spacing on a bootstrap navbar

As someone who doesn't work on front-end tasks frequently, I have encountered an issue while creating a navbar using Bootstrap. The problem arises when trying to add multiple buttons as it causes the spacing between them to appear strange. Does anyon ...

Switching the Flutter icon "style" from "type" to "rounded"

Is there a way to modify the icon "type" in Flutter? I've noticed that Flutter's material icons come in different types, such as Icons.done, Icons.done_rounded, Icons.done_sharp. For example, the types are "rounded" and "sharp", with Icons.done ...

Stylish Radial Hover Effect for Images Using CSS

I am looking to create a unique effect where upon hovering over an image, color will be applied in a radial shape on a grayscaled image within a div that is pointed by the cursorhttps://i.sstatic.net/64RJv.jpg Below you can see the desired outcome compare ...

How can I create a static navigation bar and sidebar using Bootstrap 4?

Currently, I am utilizing HTML, Javascript, Bootstrap, and CSS to develop a fixed navbar and sidebar for our system. My objective is to ensure that the navbar and sidebar remain fixed even when users scroll down the page, while also maintaining responsiven ...

The jQuery toggleClass() function is not being applied successfully to content that is dynamically generated from

I've created an awesome collection of CSS-generated cards containing icons and text with a cool animation that expands upon tapping to reveal more icons and options. I carefully crafted the list to look and behave exactly how I wanted it to. But now, ...

Are there any methods available to adjust the size of a View component in react-native?

My react-native application includes a View that contains several components. The layout displays perfectly on iPhone 6 and 5 models, but on an iPhone 4s, the bottom of one component is being clipped slightly. I'm aware of scaling base64 icons, but I ...

JavaScript takes the spotlight before CSS

Currently experiencing this issue in Chrome, although Firefox seems to be working fine so far. Here is a greatly simplified version of the problem: HTML: <div class="thumbnail"> <a href='#' id="clickMe">Click me!</a> </d ...

The functionality of the CSS transform property seems to be malfunctioning

My HTML and CSS code displays texts in two blocks within a dl element. I attempted to change the ▶ symbol to a different shape using the css transform scale property. However, some browsers only show the triangle in the first column. Why is this happenin ...

Getting rid of padding in Material UI SwipeableViews in React

Seeking assistance with the React Tabs/SwipeableViews component. I used the MaterialUI Tabs as a reference and it mostly works fine. However, I am facing a minor issue with padding in the content section. Current outcome: Current Outcome The button ...

Encountering issues while attempting to deploy React App on Git Hub Pages

After attempting to follow a ReactJS tutorial, I encountered an error when trying to deploy the code on Github pages. Despite searching for solutions, nothing seems to be working. Given my limited experience with Git and GitHub, I would greatly appreciat ...

Modify the CSS color attribute interactively by clicking

I have a function that can generate random colors. I would like to utilize this function along with jQuery's toggleClass feature to change the color of a table cell when clicked, and revert it back to its original color if clicked again. Here is the ...

404 Error: The POST Route for Express, React, and Node.js Cannot Be Located

I encountered an issue while trying to upload a file through a post request, resulting in the following error: POST http://localhost:8080/api/files 404 (Not found). The URL of the page I'm attempting to upload the file from is http://localhost:808 ...

What could be causing my React Component to consistently display the identical state?

I am currently experimenting with React and React Router to pass variables down to my RPGComponent. For this example, I am attempting to pass a gameId. When I click on each link, I expect to receive one of the following based on the link(route) clicked: ...

What is the best way to incorporate my qualifications into getServerSideProps in Nextjs?

When using the async function getServerSideProps, I am encountering an issue where the credentials are not included in the fetch request to instantiate a session. Here is the code snippet: export async function getServerSideProps({ query: { id } }) { // ...

Converting a string to regular text in JavaScript (specifically in ReactJS)

When I fetch data from an API, sometimes there are special characters involved. For example, the object returned may look like this: { question : "In which year did the British television series &quot;The Bill&quot; end?" } If I save t ...

The side navigation panel transition is stuck and failing to slide out as intended

My element is able to slide in smoothly, but encounters trouble when attempting to slide back out. I suspect the issue lies within the syntax for "display: none". Any assistance or recommendations would be greatly appreciated, and feel free to request more ...

Customize JqGrid Edit/Delete button CSS style

Within my JQGrid, I have successfully implemented Edit and Delete buttons that redirect users to another page for editing or deleting specific records. However, I am facing a CSS issue with the styling of these buttons. How can I override the current style ...

React Router relies on a DOM for Browser History to function properly

I am currently developing my app using React.js and express. My main focus right now is setting up react-router-dom for the application. Unfortunately, I encountered a warning when attempting to run the app: Invariant Violation: Browser history needs a ...

Guide on transforming BinData into an Image and showcasing it on a React front end

I need to display images on the React front end that are currently in BinData format from MongoDB. The response object and data look like this. I tried passing the binary data in the src attribute of the img element with the mimetype and data encoding type ...