卡片
Bootstrap 的卡片提供了一个灵活且可扩展的内容容器,具有多种变体和选项。
基本示例
结果
加载中...
实时编辑器
import Button from 'react-bootstrap/Button';import Card from 'react-bootstrap/Card';function BasicExample() {return (<Card style={{ width: '18rem' }}><Card.Img variant="top" src="holder.js/100px180" /><Card.Body><Card.Title>Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text><Button variant="primary">Go somewhere</Button></Card.Body></Card>);}export default BasicExample;
内容类型
主体
使用 <Card.Body>
在 <Card>
内填充内容。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function BodyOnlyExample() {return (<Card><Card.Body>This is some text within a card body.</Card.Body></Card>);}export default BodyOnlyExample;
或者,您可以使用此简写版本,用于只有主体且没有其他子元素的卡片
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function BodyShorthandExample() {return <Card body>This is some text within a card body.</Card>;}export default BodyShorthandExample;
标题、文本和链接
在 <Card.Body>
内使用 <Card.Title>
、<Card.Subtitle>
和 <Card.Text>
将它们整齐地排列起来。<Card.Link>
用于将链接彼此并排排列。
<Card.Text>
会在内容周围输出 <p>
标签,因此您可以使用多个 <Card.Text>
来创建单独的段落。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function TextExample() {return (<Card style={{ width: '18rem' }}><Card.Body><Card.Title>Card Title</Card.Title><Card.Subtitle className="mb-2 text-muted">Card Subtitle</Card.Subtitle><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text><Card.Link href="#">Card Link</Card.Link><Card.Link href="#">Another Link</Card.Link></Card.Body></Card>);}export default TextExample;
列表组
使用平铺列表组在卡片中创建内容列表。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';import ListGroup from 'react-bootstrap/ListGroup';function ListGroupExample() {return (<Card style={{ width: '18rem' }}><ListGroup variant="flush"><ListGroup.Item>Cras justo odio</ListGroup.Item><ListGroup.Item>Dapibus ac facilisis in</ListGroup.Item><ListGroup.Item>Vestibulum at eros</ListGroup.Item></ListGroup></Card>);}export default ListGroupExample;
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';import ListGroup from 'react-bootstrap/ListGroup';function ListGroupWithHeaderExample() {return (<Card style={{ width: '18rem' }}><Card.Header>Featured</Card.Header><ListGroup variant="flush"><ListGroup.Item>Cras justo odio</ListGroup.Item><ListGroup.Item>Dapibus ac facilisis in</ListGroup.Item><ListGroup.Item>Vestibulum at eros</ListGroup.Item></ListGroup></Card>);}export default ListGroupWithHeaderExample;
百宝箱
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';import ListGroup from 'react-bootstrap/ListGroup';function KitchenSinkExample() {return (<Card style={{ width: '18rem' }}><Card.Img variant="top" src="holder.js/100px180?text=Image cap" /><Card.Body><Card.Title>Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body><ListGroup className="list-group-flush"><ListGroup.Item>Cras justo odio</ListGroup.Item><ListGroup.Item>Dapibus ac facilisis in</ListGroup.Item><ListGroup.Item>Vestibulum at eros</ListGroup.Item></ListGroup><Card.Body><Card.Link href="#">Card Link</Card.Link><Card.Link href="#">Another Link</Card.Link></Card.Body></Card>);}export default KitchenSinkExample;
页眉和页脚
您可以通过添加 <Card.Header>
组件来添加页眉。
结果
加载中...
实时编辑器
import Button from 'react-bootstrap/Button';import Card from 'react-bootstrap/Card';function WithHeaderExample() {return (<Card><Card.Header>Featured</Card.Header><Card.Body><Card.Title>Special title treatment</Card.Title><Card.Text>With supporting text below as a natural lead-in to additional content.</Card.Text><Button variant="primary">Go somewhere</Button></Card.Body></Card>);}export default WithHeaderExample;
可以通过将标题元素传递给 <as>
属性来设置 <CardHeader>
的样式。
结果
加载中...
实时编辑器
import Button from 'react-bootstrap/Button';import Card from 'react-bootstrap/Card';function WithHeaderStyledExample() {return (<Card><Card.Header as="h5">Featured</Card.Header><Card.Body><Card.Title>Special title treatment</Card.Title><Card.Text>With supporting text below as a natural lead-in to additional content.</Card.Text><Button variant="primary">Go somewhere</Button></Card.Body></Card>);}export default WithHeaderStyledExample;
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function WithHeaderAndQuoteExample() {return (<Card><Card.Header>Quote</Card.Header><Card.Body><blockquote className="blockquote mb-0"><p>{' '}Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integerposuere erat a ante.{' '}</p><footer className="blockquote-footer">Someone famous in <cite title="Source Title">Source Title</cite></footer></blockquote></Card.Body></Card>);}export default WithHeaderAndQuoteExample;
结果
加载中...
实时编辑器
import Button from 'react-bootstrap/Button';import Card from 'react-bootstrap/Card';function HeaderAndFooterExample() {return (<Card className="text-center"><Card.Header>Featured</Card.Header><Card.Body><Card.Title>Special title treatment</Card.Title><Card.Text>With supporting text below as a natural lead-in to additional content.</Card.Text><Button variant="primary">Go somewhere</Button></Card.Body><Card.Footer className="text-muted">2 days ago</Card.Footer></Card>);}export default HeaderAndFooterExample;
图像
卡片包含一些用于处理图像的选项。您可以选择在卡片的任一端追加“图像标题”,将图像与卡片内容叠加,或者只是将图像嵌入卡片中。
图像标题
与页眉和页脚类似,卡片可以包含顶部和底部的“图像标题”——卡片顶部或底部的图像。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function ImageAndTextExample() {return (<><Card><Card.Img variant="top" src="holder.js/100px180" /><Card.Body><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card><Card.Body><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body><Card.Img variant="bottom" src="holder.js/100px180" /></Card></>);}export default ImageAndTextExample;
图像叠加
将图像变成卡片背景并叠加卡片的文本。根据图像,您可能需要或不需要额外的样式或实用程序。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function ImgOverlayExample() {return (<Card className="bg-dark text-white"><Card.Img src="holder.js/100px270" alt="Card image" /><Card.ImgOverlay><Card.Title>Card title</Card.Title><Card.Text>This is a wider card with supporting text below as a natural lead-into additional content. This content is a little bit longer.</Card.Text><Card.Text>Last updated 3 mins ago</Card.Text></Card.ImgOverlay></Card>);}export default ImgOverlayExample;
导航
使用 React Bootstrap 的 Nav 组件,在卡片的页眉(或块)中添加一些导航。
结果
加载中...
实时编辑器
import Button from 'react-bootstrap/Button';import Card from 'react-bootstrap/Card';import Nav from 'react-bootstrap/Nav';function NavTabsExample() {return (<Card><Card.Header><Nav variant="tabs" defaultActiveKey="#first"><Nav.Item><Nav.Link href="#first">Active</Nav.Link></Nav.Item><Nav.Item><Nav.Link href="#link">Link</Nav.Link></Nav.Item><Nav.Item><Nav.Link href="#disabled" disabled>Disabled</Nav.Link></Nav.Item></Nav></Card.Header><Card.Body><Card.Title>Special title treatment</Card.Title><Card.Text>With supporting text below as a natural lead-in to additional content.</Card.Text><Button variant="primary">Go somewhere</Button></Card.Body></Card>);}export default NavTabsExample;
结果
加载中...
实时编辑器
import Button from 'react-bootstrap/Button';import Card from 'react-bootstrap/Card';import Nav from 'react-bootstrap/Nav';function NavPillsExample() {return (<Card><Card.Header><Nav variant="pills" defaultActiveKey="#first"><Nav.Item><Nav.Link href="#first">Active</Nav.Link></Nav.Item><Nav.Item><Nav.Link href="#link">Link</Nav.Link></Nav.Item><Nav.Item><Nav.Link href="#disabled" disabled>Disabled</Nav.Link></Nav.Item></Nav></Card.Header><Card.Body><Card.Title>Special title treatment</Card.Title><Card.Text>With supporting text below as a natural lead-in to additional content.</Card.Text><Button variant="primary">Go somewhere</Button></Card.Body></Card>);}export default NavPillsExample;
卡片样式
背景颜色
您可以通过更改卡片的 <bg>
和 <text>
属性来更改卡片的外观。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function BgColorExample() {return (<>{['Primary','Secondary','Success','Danger','Warning','Info','Light','Dark',].map((variant) => (<Cardbg={variant.toLowerCase()}key={variant}text={variant.toLowerCase() === 'light' ? 'dark' : 'white'}style={{ width: '18rem' }}className="mb-2"><Card.Header>Header</Card.Header><Card.Body><Card.Title>{variant} Card Title </Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card>))}</>);}export default BgColorExample;
边框颜色
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';function BorderExample() {return (<><Card border="primary" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Primary Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="secondary" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Secondary Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="success" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Success Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="danger" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Danger Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="warning" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Warning Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="info" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Info Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="dark" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Dark Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /><Card border="light" style={{ width: '18rem' }}><Card.Header>Header</Card.Header><Card.Body><Card.Title>Light Card Title</Card.Title><Card.Text>Some quick example text to build on the card title and make up thebulk of the card's content.</Card.Text></Card.Body></Card><br /></>);}export default BorderExample;
卡片布局
卡片组
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';import CardGroup from 'react-bootstrap/CardGroup';function GroupExample() {return (<CardGroup><Card><Card.Img variant="top" src="holder.js/100px160" /><Card.Body><Card.Title>Card title</Card.Title><Card.Text>This is a wider card with supporting text below as a natural lead-into additional content. This content is a little bit longer.</Card.Text></Card.Body><Card.Footer><small className="text-muted">Last updated 3 mins ago</small></Card.Footer></Card><Card><Card.Img variant="top" src="holder.js/100px160" /><Card.Body><Card.Title>Card title</Card.Title><Card.Text>This card has supporting text below as a natural lead-in toadditional content.{' '}</Card.Text></Card.Body><Card.Footer><small className="text-muted">Last updated 3 mins ago</small></Card.Footer></Card><Card><Card.Img variant="top" src="holder.js/100px160" /><Card.Body><Card.Title>Card title</Card.Title><Card.Text>This is a wider card with supporting text below as a natural lead-into additional content. This card has even longer content than thefirst to show that equal height action.</Card.Text></Card.Body><Card.Footer><small className="text-muted">Last updated 3 mins ago</small></Card.Footer></Card></CardGroup>);}export default GroupExample;
网格卡片
使用 Row
的 网格列 属性来控制每行显示的卡片数量。
结果
加载中...
实时编辑器
import Card from 'react-bootstrap/Card';import Col from 'react-bootstrap/Col';import Row from 'react-bootstrap/Row';function GridExample() {return (<Row xs={1} md={2} className="g-4">{Array.from({ length: 4 }).map((_, idx) => (<Col key={idx}><Card><Card.Img variant="top" src="holder.js/100px160" /><Card.Body><Card.Title>Card title</Card.Title><Card.Text>This is a longer card with supporting text below as a naturallead-in to additional content. This content is a little bitlonger.</Card.Text></Card.Body></Card></Col>))}</Row>);}export default GridExample;