css - Bootstrap 4 - 水平和垂直对齐

标签 css bootstrap-4

<分区>

我无法同时水平和垂直对齐以下内容。

有人能告诉我最好的方法吗?

    <div class="container">

  <div class="row">

    <div class="col-md-4">
      <img width="300" src="../assets/medlogo.png">

      <h1 class="text-center login-title">Acessar o programa</h1>
      <div class="account-wall">
        <img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
          alt="">
        <form class="form-signin">
          <input type="text" class="form-control" placeholder="Email" required autofocus>
          <input type="password" class="form-control" placeholder="Password" required>
          <button class="btn btn-lg btn-primary btn-block" type="submit">
                  Sign in</button>
        </form>
      </div>

    </div>
  </div>
</div>

谢谢

最佳答案

Bootstrap4 现在使用 css Flexbox,所以你可以使用相同的。 Flexbox 具有开箱即用的垂直和水平对齐支持。

基本上, flex 盒容器可以将 flex-direction 作为 row(默认值)或 column。对于前者,属性 align-items 可用于垂直对齐其子项,而 justify-content 可用于水平对齐。对于后者,align-items 用于水平对齐,justify-content 用于垂直对齐。

您可以在此处阅读有关 Flexbox 的更多信息:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

关于css - Bootstrap 4 - 水平和垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46637199/

上一篇:调整大小的 HTML Canvas 最佳实践

下一篇:html - 我的 CSS 文件没有链接到我的 HTML 文件,即使它们在同一个文件夹中

相关文章:

html - 将图像作为背景会减慢页面的运行速度吗

css - 在 :first-letter in Firefox and IE 上变换比例

javascript - Bootstrap 4 关闭模式,背景不会消失

html - 如何并排对齐餐厅菜单的标题?

html - 如何使用 CSS 过渡来增加悬停时 Bootstrap 卡片的字体大小?

html - 带有 x 滚动的 CSS 绝对位置

html - 输入复选框默认选中

css - 使用 SASS for 循环定义变量颜色

javascript - 为什么 window.scrollTo() 没有被调用?

css - 将除一类以外的所有字体设置为特定字体