使用 Boostrap 连续 4 列

LeR*_*ur1 1 html bootstrap-4

我正在使用 Bootstrap 4.5.1 来显示 4 列,看起来像这样。

我的 4 列的实际显示。

1

我希望这 4 列在一行中对齐(它们不应该换行)。

这是代码:

html

<div class="container flex-nowrap">
            <div class="featured-boxes">
                <div class="row">
                    <a href="<?= $this->Url->build(['controller' => 'Academy' , 'action' => 'index', 'language' => $this->request->getSession()->read('Config.language')]); ?>">
                        <div class="col-sm">
                            <div class="featured-box featured-box-primary featured-box-effect-1 mt-xlg" style="height: 358px;">
                                <div class="box-content">
                                    <i class="icon-featured fa fa-graduation-cap"></i>
                                    <h4 class="text-uppercase"><?= __('Academy'); ?></h4>
                                    <p><?= __(''); ?></p>
                                    <?= $this->Html->image('academy.png', ['alt' =>  __('Academy'), 'class' => 'img-responsive img-rounded']); ?>
                                </div>
                            </div>
                        </div>
                    </a>
                    <a href="<?= $this->Url->build(['controller' => 'Esports' , 'action' => 'index', 'language' => $this->request->getSession()->read('Config.language')]); ?>">
                        <div class="col-sm">
                            <div class="featured-box featured-box-primary featured-box-effect-1 mt-xlg" style="height: 358px;">
                                <div class="box-content">
                                    <i class="icon-featured fa fa-gamepad"></i>
                                    <h4 class="text-uppercase"><?= __('Esports'); ?></h4>
                                    <p><?= __(''); ?></p>
                                    <?= $this->Html->image('esports.png', ['alt' => __('Esports')]); ?>
                                </div>
                            </div>
                        </div>
                    </a>
                    <a href="<?= $this->Url->build(['controller' => 'Posts','action' => 'view','bar']); ?>">
                        <div class="col-sm">
                            <div class="featured-box featured-box-primary featured-box-effect-1 mt-xlg" style="height: 358px;">
                                <div class="box-content">
                                    <i class="icon-featured fa fa-trophy"></i>
                                    <h4 class="text-uppercase"><?= __('Events'); ?></h4>
                                    <p><?= __(''); ?></p>
                                    <?= $this->Html->image('events.png', ['alt' => __('Events')]); ?>
                                </div>
                            </div>
                        </div>
                    </a>
                    <a href="<?= $this->Url->build(['controller' => 'Posts','action' => 'view','bar']); ?>">
                        <div class="col-sm">
                            <div class="featured-box featured-box-primary featured-box-effect-1 mt-xlg" style="height: 358px;">
                                <div class="box-content">
                                    <i class="icon-featured fa fa-group"></i>
                                    <h4 class="text-uppercase"><?= __('Gaming'); ?></h4>
                                    <p><?= __(''); ?></p>
                                    <?= $this->Html->image('gaming.png', ['alt' => __('Gaming')]); ?>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>
            </div>
Run Code Online (Sandbox Code Playgroud)

编辑:

我修改了我的代码,对行中的每一列使用col-sm-3而不是col-sm。但是现在,这些盒子不再响应。为什么?

这是我通过为每一列设置col-sm col-md-3来缩小窗口时得到的结果:

结果

编辑 2: *

我通过为我的图像使用 Boostrap img-fluid类解决了我的问题。

我怎样才能做到这一点?

Has*_*eed 5

一行由 12 列组成,覆盖整个屏幕。如果你想有4列,每列应该有3个空格。要使用的类应该是col-sm-3

<div class="row">
   <div class="col-sm-3"></div>
   <div class="col-sm-3"></div>
   <div class="col-sm-3"></div>
   <div class="col-sm-3"></div>
</div>
Run Code Online (Sandbox Code Playgroud)