最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change form.item label font size in AntD - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

5 Answers 5

Reset to default 14

There are multiple options to override style elements.

  1. You can directly override label elements from global CSS files like:
label { 
   font-size:16px;
}
  1. 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;
 }
  1. You can directly override the CSS in global.less file like

     & .ant-form-item-label {
        & > label {
         font-size: 16px;
        }
     }
    
  2. 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>
发布评论

评论列表(0)

  1. 暂无评论