【问题标题】:BS4 Cards in React with reactstrap?React 中的 BS4 卡与 reactstrap?
【发布时间】:2018-06-18 04:56:03
【问题描述】:

关于在 React 中使用卡片的几个问题。

首先,根据下面的代码,为什么这 4 张卡片不能并排放置?我忘了申请什么吗?

import React, { Component } from "react";
import { Container, Card, CardText, CardImg, CardBody, CardLink,
  CardTitle, Button, Col, Row } from 'reactstrap';

class Users extends Component {
  render() {
    return (
      <div>
        <Container>
          <Row>
            <Col>
              <Card>
              <CardImg top width="25%" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=318%C3%97180&w=318&h=180" alt="Card image cap" />
              <CardBody>
                <CardTitle>Need Help Finding Customers?</CardTitle>
                <CardText>Some quick example text to build on the card title and make up the bulk of the card's content.</CardText>
                <Button>Button</Button>
              </CardBody>
              </Card>
            </Col>
            <Col>
              <Card>
              <CardImg top width="25%" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=318%C3%97180&w=318&h=180" alt="Card image cap" />
              <CardBody>
                <CardTitle>Get help with a Moneyball activity!</CardTitle>
                <CardText>Some quick example text to build on the card title and make up the bulk of the card's content.</CardText>
                <Button>Button</Button>
              </CardBody>
              </Card>
            </Col>
            <Col>
              <Card>
              <CardImg top width="25%" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=318%C3%97180&w=318&h=180" alt="Card image cap" />
              <CardBody>
                <CardTitle>Request Moneyball in-person training</CardTitle>
                <CardText>Some quick example text to build on the card title and make up the bulk of the card's content.</CardText>
                <Button>Button</Button>
              </CardBody>
              </Card>
            </Col>
            <Col>
              <Card>
              <CardImg top width="25%" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=318%C3%97180&w=318&h=180" alt="Card image cap" />
              <CardBody>
                <CardTitle>Register for an Immerse Event</CardTitle>
                <CardText>Some quick example text to build on the card title and make up the bulk of the card's content.</CardText>
                <Button>Button</Button>
              </CardBody>
              </Card>
            </Col>
          </Row>
        </Container>
      </div>
    );
  }
}

export default Users;

我得到的是这样的:

此外,通过我在网上看到的示例,我喜欢卡片的概念,但更愿意将整个卡片制作成一个大按钮。在 React 中,有哪些最佳实践?

非常感谢。

【问题讨论】:

    标签: twitter-bootstrap reactjs bootstrap-4 jsx reactstrap


    【解决方案1】:

    reactstrap 的文档中似乎缺少“网格”系统的元素(Container、Row、Col),但快速查看一下 Col 组件的代码,我会说您需要为所需的大小。

    类似这样的:

    <Col lg="2">
    

    对于“col-lg-2”引导类,或

    <Col sm="true">
    

    对于 'col-sm' 类,没有编号。

    【讨论】:

    • 感谢您的意见。再想一想,我忘了将import 'bootstrap/dist/css/bootstrap.css'; 加载到我的index.js 中。
    猜你喜欢
    • 2018-10-23
    • 2020-10-23
    • 2023-03-21
    • 1970-01-01
    • 2021-01-12
    • 2018-01-06
    • 2020-04-04
    • 2021-08-14
    • 2021-06-21
    相关资源
    最近更新 更多