使用 bootstrap 4 网格系统将单列居中 [英] Centering a single column using bootstrap 4 grid system

查看:24
本文介绍了使用 bootstrap 4 网格系统将单列居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 bootstrap 4 网格系统将单列居中.在引导程序 3 中,我能够做到:

在 bootstrap 4 中,即使使用新的偏移类:offset-md-2,同样也不起作用.

以下有效,但页面上有空列感觉不对,只是为了将 col-md-5 居中.

<div class="col"></div><div class="col-md-5 align-self-center"><img src="img/myimage.gif" style="width: 100%;">

<div class="col"></div>

解决方案

As 根据文档,您可以在行上使用 justify-content-center 将一行中的任意数量的列居中.

<div class="col-4">一列居中

I am trying to use the bootstrap 4 grid system to center a single column. In bootstrap 3 I was able to do:

<div class="col-md-10 col-md-offset-2">
</div>

In bootstrap 4 the same does not work even when using the new offset class: offset-md-2.

The following works, but something feels wrong about having empty columns on the page, just to center a col-md-5.

<div class="row">
    <div class="col"></div>
    <div class="col-md-5 align-self-center">
        <img src="img/myimage.gif" style="width: 100%;">
    </div>
    <div class="col"></div>
</div>

解决方案

As per the documentation you can use justify-content-center on the row to center any number of columns in a row.

<div class="row justify-content-center">
  <div class="col-4">
    One centered column
  </div>
</div>

这篇关于使用 bootstrap 4 网格系统将单列居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆