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

Time:06-03

For example:

<div >
    <div >
        <div >
            <div >
                <img src="https://picsum.photos/1200/1200" alt="" >
            </div>
        </div>
        <div >
            <div >
                <h1>Text Title</h1>
            </div>
        </div>
    </div>
</div>

The sandbox code: https://codesandbox.io/s/interesting-euler-sh22vn?file=/index.html

Photo what I want: https://ibb.co/MnLQf6n

My problem is when I add fix height, the text is moving when I change screen view.

I need to vertical align the text to image center point on desktop screen.

CodePudding user response:

just add align-items-center to row and it will worce the layout to be vertically center learns about flex from here and bootstrap flex properties from here

<!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/[email protected]/dist/css/bootstrap.min.css"
      integrity="sha384-Gn5384xqQ1aoWXA 058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous"
    />

    <title>Hello, world!</title>
  </head>
  <body>
    <div >
      <div >
        <div >
          <div >
            <img
              src="https://picsum.photos/1200/1200"
              alt=""
              
            />
          </div>
        </div>
        <div >
          <div >
            <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/[email protected]/dist/umd/popper.min.js"
      integrity="sha384-ApNbgh9B Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
      integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 76PVCmYl"
      crossorigin="anonymous"
    ></script>
  </body>
</html>

CodePudding user response:

This will solve your problem.

<div >
  • Related