Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce spacing between antd Form.Items?

Tags:

reactjs

antd

How does one reduce the amount of space between two Form.Item's in a Form?

for example in any of the antd form examples the spacing between a Form.Item is all the same and (to my eye) rather large.

like image 436
Gerald Wichmann Avatar asked Jun 27 '19 01:06

Gerald Wichmann


1 Answers

You need to style the Form.Item component, for example with inline-style:

// The current form item is margin 15px top.
<Form.Item style={{ marginBottom: "0px" }}>
  <Input />
</Form.Item>

Or the entire Form by overriding the css-class, for example with CSS-in-JS:

// Apply style to all form
const StyledForm = styled(Form)`
  .ant-form-item {
    margin-bottom: 0px;
  }
`;

Demo:

Edit Q-56637063

Same can be achieved with .css file and importing it

like image 118
Dennis Vash Avatar answered Sep 26 '22 17:09

Dennis Vash