[英]How to customize the title of a card in antd
in a react app how can I change the size and the font of the title of a antd card?在 react 应用程序中,如何更改 antd 卡标题的大小和字体?
<Card title="Title" style={{ width: 300 }}> <p>Card content</p> <p>Card content</p> <p>Card content</p> </Card>
Antd has externized most of their styling variable in LESS variables Antd 已将大部分样式变量外部化为 LESS 变量
as you can see in如您所见
https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less
To be able to overwrite those variables you need to use modifyVar function from LESS为了能够覆盖这些变量,您需要使用 LESS 中的 modifyVar function
You can check more about theme updates here: https://ant.design/docs/react/customize-theme您可以在此处查看有关主题更新的更多信息: https://ant.design/docs/react/customize-theme
So to your question you can check -因此,对于您的问题,您可以检查-
@card-head-font-size: @font-size-lg; @card-head-font-size: @font-size-lg; @card-head-font-size-sm: @font-size-base
@card-head-font-size-sm: @font-size-base
For example changing the font-size
and font-family
of the title using styled-components
you can override the class like so:例如,使用
styled-components
更改标题的font-size
和font-family
,您可以像这样覆盖 class:
import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Card } from 'antd';
import styled from 'styled-components';
const StyledCard = styled(Card)`
.ant-card-head-title {
font-size: 10px;
font-family: cursive;
}
`;
ReactDOM.render(
<>
<StyledCard title="Default size card" extra={<a href="#">More</a>} style={{ width: 300 }}>
<p>Card content</p>
<p>Card content</p>
<p>Card content</p>
</StyledCard>
</>,
document.getElementById('container'),
);
According to the docs,根据文档,
You can also provide a ReactNode
for the title prop, and style it as you want.您还可以为 title 属性提供一个
ReactNode
,并根据需要设置它的样式。
You also can check this sandBox:你也可以检查这个沙盒:
https://codesandbox.io/s/basic-card-antd-4-18-5-forked-hfdnm?file=/index.js https://codesandbox.io/s/basic-card-antd-4-18-5-forked-hfdnm?file=/index.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.