Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  56] [ 3]  / answers: 1 / hits: 16605  / 5 Years ago, mon, june 17, 2019, 12:00:00

I'm trying to customize antd ant-row class within my form component so I can change the height between input fields. I have defined a different class name to my form and tried to do modify it in the css file however it's not being modified or applied. Can someone please help?



Form.js



 {this.state.active2 && (
<Form
style={{
position: 'relative',
zindex: '2',
left: '35%',
overflow: 'initial',
width: '300px',
}}
onSubmit={this.handleSubmit}
className=login-form
layout={formLayout}>

<Form.Item>
<Form.Item label=Full name {...formLayout}>
{form.getFieldDecorator('username', {
rules: [{ required: true, message: 'Please input your username!' }],
})(
<Input
prefix={<Icon type=user style={{ color: 'rgba(0,0,0,.25)' }} />}
placeholder=input placeholder
/>,
)}
</Form.Item>

</Form.Item>


styles.scss



 .login-form.ant-row {
position: relative !important;
height: 70px !important;
margin-left: 0 !important;
zoom: 1 !important;
display: block !important;
box-sizing: border-box !important;
}

More From » reactjs

 Answers
23

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


Same can be achieved with .css file and importing it:


:global .ant-form-item {
margin-bottom: 0;
}

[#51990] Monday, June 10, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaisep

Total Points: 748
Total Questions: 95
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
blaisep questions
Wed, Dec 16, 20, 00:00, 4 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
Tue, Nov 12, 19, 00:00, 5 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
;