I'm using styled components something like this
const FormItem = styled(Form.Item)`
font-size: 16px;
`;
Using Form Item something like this
<FormItem label="System Pressurized">
{getFieldDecorator('systemPressurized')(
<Select defaultValue="" placeholder="Select Type">
<Option value="Yiminghe">yiminghe</Option>
</Select>,
)}
</FormItem>
I've tried changing font size of AntD but it doesn't seem to workout
I'm using styled components something like this
const FormItem = styled(Form.Item)`
font-size: 16px;
`;
Using Form Item something like this
<FormItem label="System Pressurized">
{getFieldDecorator('systemPressurized')(
<Select defaultValue="" placeholder="Select Type">
<Option value="Yiminghe">yiminghe</Option>
</Select>,
)}
</FormItem>
I've tried changing font size of AntD but it doesn't seem to workout
Share Improve this question asked Apr 22, 2019 at 11:16 Afaq Ahmed KhanAfaq Ahmed Khan 2,3022 gold badges31 silver badges41 bronze badges 2- you want to change formItem label or option label??? – sathish kumar Commented Apr 22, 2019 at 11:19
- I want to change formItem label – Afaq Ahmed Khan Commented Apr 22, 2019 at 11:24
5 Answers
Reset to default 14There are multiple options to override style elements.
- You can directly override label elements from global CSS files like:
label {
font-size:16px;
}
- Individual element by adding a script to the label element:
<FormItem
label={ <p style={{fontSize:"16px"}}>"System Pressurized"</p> }>
{ getFieldDecorator('systemPressurized')(
<Select defaultValue="" placeholder="Select Type">
<Option value="Yiminghe">yiminghe</Option>
</Select>
)}
</FormItem>
Please override CSS in your code like
$ .ant-form-item-label>label {
font-size: 16px;
}
You can directly override the CSS in global.less file like
& .ant-form-item-label { & > label { font-size: 16px; } }
You can write JSX for this
<FormItem label = { <p style={{fontSize: "16px"}}>System Pressurized</p>}> {getFieldDecorator('systemPressurized')( <Select defaultValue="" placeholder="Select Type"> <Option value="Yiminghe">yiminghe</Option> </Select>, )}
add css:
.ant-form-item-label label{
font-size: 16px;
}
you have two way to style the formItem label
//way one :
//You can override the default css by override below selectors
.form-section .form-group label{
font-size : 20px
//YOUR CUSTOM STYLE
}
// way two :
// You can pass custom component like below :
<FormItem label={<p style={YOURCUSTOMSTYLEOBJECT}>System Pressurized</p>}>
{getFieldDecorator('systemPressurized')(
<Select defaultValue="" placeholder="Select Type">
<Option value="Yiminghe">yiminghe</Option>
</Select>,
)}
</FormItem>
then use it like this
<!-- language: lang-js -->
const formItemLayout =
formLayout === 'horizontal' ?
{
labelCol: {
span: 4,
style: {
"text-align": "left",
"font-size": "12px"
}
},
wrapperCol: {
span: 30,
},
} :
null;
<!-- end snippet -->
//then use it like this
<Form
{...formItemLayout}
layout={formLayout}
form={form}
initialValues={{
layout: formLayout,
}}
>
<Form.Item
label={"Full Name"}
name="username"
id="name"
style={{ display: "flex", flexDirection: "column" }}
defaultValue={name}
onChange={handleChange()}
rules={[
{
required: true,
message: 'Please input your name!',
},
]}
>
<Input />
</Form.Item>
</Form>