如何将 bootstrap 列的文本垂直对齐到图像中心点

How to vertical align bootstrap column's text to image center point

例如:

<div class="container">
    <div class="row">
        <div class="col-lg-8">
            <div class="image">
                <img src="https://picsum.photos/1200/1200" alt="" class="img-fluid">
            </div>
        </div>
        <div class="col-lg-4">
            <div class="text">
                <h1>Text Title</h1>
            </div>
        </div>
    </div>
</div>

沙盒代码: https://codesandbox.io/s/interesting-euler-sh22vn?file=/index.html

拍下我想要的: https://ibb.co/MnLQf6n

我的问题是,当我添加固定高度时,当我更改屏幕视图时文本会移动。

我需要将文本垂直对齐到桌面屏幕上的图像中心点。

只需将 align-items-center 添加到行,它就会使布局垂直居中 从 here and bootstrap flex properties from here

了解 flex

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />

    <!-- Bootstrap CSS -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
      integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous"
    />

    <title>Hello, world!</title>
  </head>
  <body>
    <div class="container">
      <div class="row align-items-center">
        <div class="col-8">
          <div class="image">
            <img
              src="https://picsum.photos/1200/1200"
              alt=""
              class="img-fluid"
            />
          </div>
        </div>
        <div class="col-4">
          <div class="text">
            <h1>Text Title</h1>
          </div>
        </div>
      </div>
    </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script
      src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
      integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js"
      integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js"
      integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
      crossorigin="anonymous"
    ></script>
  </body>
</html>

这将解决您的问题。

<div class="row align-items-center">