垂直对齐中心div引导程序4

时间:2019-01-28 07:25:26

标签: bootstrap-4

我正在尝试使用Bootstrap 4将Container放在页面中间。

<section id="film">
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <div class="card-body">
                    <img src="images\laravel.jpg" class="img-fluid">
                </div>
            </div>
            <div class="col-md-6">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <img src="images\logo.png" class="img-fluid">
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

justify-content-center将表单水平对齐,但是我不知道如何垂直对齐表单。我曾尝试使用align-items-centeralign-self-center,但这是行不通的。

我想念什么?

vertical aligin

1 个答案:

答案 0 :(得分:2)

将类align-self-center添加到 col 元素而不是卡身

查看此内容:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<section id="film">
    <div class="container">
        <div class="row">
            <div class="col-6 align-self-center">
                <div class="card-body">
                    <img src="https://viettelpay.vn/assets/img/website/anh%20thumb.jpg" class="img-fluid">
                </div>
            </div>
            <div class="col-6 align-self-center">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <img src="https://www.drupalexp.com/sites/all/themes/dexp_drupalexp/logo.svg" class="img-fluid">
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>