html - 使用 Boostrap 连续 4 列
问题描述
我正在使用 Bootstrap 4.5.1 显示 4 列,如下所示。
我的 4 列的实际显示。
我希望这 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>
编辑:
我修改了代码以对行中的每一列使用col-sm-3而不是col-sm 。但是现在,这些盒子不再响应了。为什么?
这是通过为每一列设置col-sm col-md-3来缩小窗口时得到的结果:
编辑2: *
我通过对图像使用 Boostrap img-fluid类解决了我的问题。
我怎样才能做到这一点?
解决方案
一行由 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>
推荐阅读
- syntax - Cobol 的语法帮助
- android - 每次滚动列表时,毕加索图像都会在列表视图中重新加载
- security - 由于 odoo12 POS 中的安全限制,请求的操作无法完成?
- r - 从 R 中的分组数据中选择 n 个随机组
- c++ - WinAPI - 钩住鼠标
- python-3.x - 将 GUI 合并到我的裁剪和堆栈程序中
- spring-boot - IntelliJ 无法识别 Kotlin JPA 插件
- wordpress - 如何通过所有帖子运行我的 php 程序?
- c# - 转换器未通过两种方式绑定到文本属性的自定义用户控件内的文本框取消焦点转换回
- android-studio - 将另一个活动更改为主活动和新项目 - Android Studio