【问题标题】:How to center align a bootstrap 4 card horizontal and vertical using bootstrap classes in the row and column? [duplicate]如何使用行和列中的引导类将引导 4 卡水平和垂直居中对齐? [复制]
【发布时间】:2020-12-08 10:45:01
【问题描述】:

我看过多个如何将引导卡居中的示例,但没有一个适合我的需要。我正在尝试将引导卡垂直和水平居中,以便将卡准确放置在屏幕的中心。我想通过仅使用 mx-auto 等引导类来实现这一点。我已经尝试了几个小时但还没有找到解决方案,这是我正在使用的代码:

<div class="row">
<div class="col-lg-3 col-md-3 col-sm-12">
    <div class="card h-100 login-card">
        <div class="card-body">
            <h5 class="card-title">Login</h5>
            <h6 class="card-subtitle text-muted">You can login here</h6>
        </div>
        <table class="table table-borderless table-hover h-75">
            <tr>
                <td>Test</td>
            </tr>
            <tr>
                <td>Test</td>
            </tr>
            <tr>
                <td>Test</td>
            </tr>
            <tr>
                <td>Test</td>
            </tr>
        </table>
    </div>
</div>

结果如下:

我想得到什么:

希望有人可以帮助我并找到实现此目标的最佳解决方案!

谢谢!

【问题讨论】:

  • 在codepen上写代码或添加css代码

标签: css twitter-bootstrap bootstrap-4 center


【解决方案1】:

CSS:

 .row{
    height: 100vh;
 }

HTML:

<div class="row d-flex justify-content-center align-items-center">
        <div class="col-lg-3 col-md-3 col-sm-12">
            <div class="card h-100 login-card">
                <div class="card-body">
                    <h5 class="card-title">Login</h5>
                    <h6 class="card-subtitle text-muted">You can login here</h6>
                </div>
                <table class="table table-borderless table-hover h-75">
                    <tr>
                        <td>Test</td>
                    </tr>
                    <tr>
                        <td>Test</td>
                    </tr>
                    <tr>
                        <td>Test</td>
                    </tr>
                    <tr>
                        <td>Test</td>
                    </tr>
                </table>
            </div>
        </div>

【讨论】:

    猜你喜欢
    • 2019-07-10
    • 1970-01-01
    • 2018-08-09
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多