簡體   English   中英

antd中如何自定義一張卡片的標題

[英]How to customize the title of a card in antd

在 react 應用程序中,如何更改 antd 卡標題的大小和字體?

 <Card title="Title" style={{ width: 300 }}> <p>Card content</p> <p>Card content</p> <p>Card content</p> </Card>

Antd 已將大部分樣式變量外部化為 LESS 變量

如您所見

https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less

為了能夠覆蓋這些變量,您需要使用 LESS 中的 modifyVar function

您可以在此處查看有關主題更新的更多信息: https://ant.design/docs/react/customize-theme

因此,對於您的問題,您可以檢查-
@card-head-font-size: @font-size-lg; @card-head-font-size-sm: @font-size-base

例如,使用styled-components更改標題的font-sizefont-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'),
);

根據文檔,
您還可以為 title 屬性提供一個ReactNode ,並根據需要設置它的樣式。

你也可以檢查這個沙盒:
https://codesandbox.io/s/basic-card-antd-4-18-5-forked-hfdnm?file=/index.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM