最近的react项目中在使用Antd时,使用Form表时Form.Item的label标签时发现默认的字体颜色是白色,并且给其所属的类添加颜色并加上!impotant也没有生效,最后在搜索很久后发现label的字体是加在了Label标签的title属性上,最终得到了两种解决方案:
1.利用[attrname:attrvalue]选择器的方法:
<Form.Item
label="新闻标题"
name="title"
rules={[ { required: true, message: 'Please input your username!', }, ]}
>
<Input />
</Form.Item>
//外部css文件中加上
[title="新闻标题"] {
color: #000 !important;
}
2.通过直接对label添加标签的形式:
<Form.Item
label={<label style={{ color: "#000" }}>新闻标题</label>}
name="title"
rules={[ { required: true, message: 'Please input your username!', }, ]}
>
<Input />
</Form.Item>