css - 使 ReactStrap/Bootstrap4 卡片在不同的列中具有相同的高度

标签 css bootstrap-4 reactstrap

我在 https://codesandbox.io/s/426277vml9 有一个例子.我使用单独的列,因为我希望它们以低分辨率堆叠。

显然,现在,高度是内容的函数,因此它们是不相等的。有什么办法(除了施加固定高度之外)让它们自动对齐到相同的高度吗?

  <Container fluid className="full-height bg-light">
      <Row className="h-100 justify-content-center full-height align-items-center bg-light">
        <Col xs="10" lg="3" className="p-0">
          <Card>
            <CardBody>
              <CardTitle>LOGIN</CardTitle>
              <CardText>Sign in with your account.</CardText>
              <InputGroup className="mb-3">
                <div className="input-group-prepend">
                  <span className="input-group-text">
                    <i className="icon-user"></i>
                  </span>
                </div>
                <Input type="text" placeholder="Username"/>
              </InputGroup>
              <InputGroup className="mb-4">
                <div className="input-group-prepend">
                  <span className="input-group-text">
                    <i className="icon-lock"></i>
                  </span>
                </div>
                <Input type="password" placeholder="Password"/>
              </InputGroup>
              <Row>
                <Col xs="12" lg="6">
                  <Button color="primary" className="px-4">Login</Button>
                </Col>
                <Col xs="12" lg="6" className="text-right">
                  <Button color="link" className="px-0">Forgot password?</Button>
                </Col>
              </Row>
            </CardBody>
          </Card>
        </Col>
        <Col xs="10" lg="3" className="p-0">
          <Card color="primary">
            <CardBody className="text-white">
              <CardTitle>CREATE ACCOUNT</CardTitle>
              <CardText>If you want to create an account for your company to start using this product, click on the Create button. If your organization already has an account and you'd like to join it, click on the "Join" button.</CardText>
              <Row>
                <Col xs="12" md="6">
                  <Button color="success" className="px-4">Create</Button>
                </Col>
                <Col xs="12" md="6" className="text-right">
                  <Button color="success" className="px-4">Join</Button>
                </Col>
              </Row>
            </CardBody>
          </Card>
        </Col>
      </Row>
    </Container>

最佳答案

为了实现这一点,您必须稍微修改您的标记。您将在下面找到示例标记。这是分割:

  • .justify-content-center 类与 .align-items-center 类分开,方法是将后者应用到带有 .container-fluid< 的 div 上 并向这个外部 div 添加一个 .d-flex
  • 您现在可以从 .row 中删除 .h-100 .full-height .bg-light 类。
  • 通过此设置,带有 .col-10 的 div 将具有相同的高度,因此唯一剩下的就是将 h-100 放在 .card,让它们填满垂直空间。

.full-height {
    min-height:100vh;
}
<div id="root">
    <div class="container-fluid d-flex full-height align-items-center bg-light">
        <div class="row justify-content-center">
            <div class="p-0 col-10 col-lg-3">
                <div class="card h-100">
                    <div class="card-body">
                        <h4 class="card-title">LOGIN</h4>
                        <p class="card-text">Sign in with your account.</p>
                        <div class="mb-3 input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text"><i class="icon-user"></i></span>
                            </div>
                            <input placeholder="Username" class="form-control" type="text">
                        </div>
                        <div class="mb-4 input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text"><i class="icon-lock"></i></span>
                            </div>
                            <input placeholder="Password" class="form-control" type="password">
                        </div>
                        <div class="row">
                            <div class="col-12 col-lg-6">
                                <button class="px-4 btn btn-primary">Login</button>
                            </div>
                            <div class="text-right col-12 col-lg-6">
                                <button class="px-0 btn btn-link">Forgot password?</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="p-0 col-10 col-lg-3">
                <div class="card h-100 bg-primary">
                    <div class="text-white card-body">
                        <h4 class="card-title">CREATE ACCOUNT</h4>
                        <p class="card-text">If you want to create an account for your company to start using this product, click on the Create button. If your organization already has an account and you'd like to join it, click on the "Join" button.</p>
                        <div class="row">
                            <div class="col-12 col-md-6">
                                <button class="px-4 btn btn-success">Create</button>
                            </div>
                            <div class="text-right col-12 col-md-6">
                                <button class="px-4 btn btn-success">Join</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

关于css - 使 ReactStrap/Bootstrap4 卡片在不同的列中具有相同的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48567158/

相关文章:

javascript - jquery输入:checked show and hide div function

javascript - 更改 div 内容 - 广告底部/顶部

javascript - 带有 Font Awesome 控件的 Bootstrap 4.1.0 轮播,但悬停在控件上会使它们消失

javascript - 在 React js 中使用 Reactstrap 从多个选择下拉列表中动态选择选项

reactjs - Reactstrap - create-react-app - 未找到 bootstrap/dist/css/bootstrap.css - v.4

html - 显示 :table versus using tables

css - 父div中的子div,float :left

javascript - Bootstrap 卡不能一直 flex 到全宽

html - 如何在 Bootstrap 列表组中创建图标列和联系信息列?

javascript - 如何使用 CDN 链接使用 Reactstrap