Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set padding to 0 on Material UI Button

I'm using a normal Button from Material-UI for React tried adding the following style

button: {
    display: 'inline-block',
    padding:0
  }

to this button

<Button className={classes.button}> I'm a Test Button </Button>

What I obtain is that the padding for the right/left side is correctly set to 0, while the one for top/bottom is not updated, see the attached image.

Is this a bug? Or what's the correct way to achieve this?

EDIT: Material-UI version: v1.0.0-beta.20

enter image description here

like image 356
r4id4 Avatar asked Nov 08 '17 22:11

r4id4


People also ask

How do I set padding in material UI?

To add padding and margin to all React Material-UI components, we can use the Box component. We use Material UI's Box component to add a container with margin and padding. We set the margin on all sides with the m prop and we set the top padding with the pt prop.

How do you put a space between buttons in material UI?

if you want to create a space between buttons you can give one button a margin-attribute. will create a 10px space between the two buttons. Show activity on this post. You need Material UI Box Component for this with display="flex" and justifyContent="space-between" .

How do you remove padding from grid MUI?

MUI Grid Remove Padding Here are two steps to completely remove padding from the MUI Grid: Completely remove the spacing prop (or set spacing={0}) Make sure no padding is applied in the sx prop or classes.

What is P in box material UI?

Box in Material-UI comes with many predefined properties such as bgcolor (background-color) , display , m (margin) , p (padding) , width , height , and a lot more.


2 Answers

This behavior is caused by the min-height and min-width properties of the root key of the Button element. Setting minHeight: 0 and/or minWidth:0 should fix it:

button: {
    display: 'inline-block',
    padding:0,
    minHeight: 0,
    minWidth: 0,
  }
like image 126
Brunno Vodola Martins Avatar answered Sep 30 '22 05:09

Brunno Vodola Martins


This answer is more accurate than @Brunno

<Button sx={{ minHeight: 0, minWidth: 0, padding: 0 }}>My Button</Button>
like image 22
iamtheasad Avatar answered Sep 30 '22 05:09

iamtheasad