简体   繁体   English

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

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

For example:例如:

<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>

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

Photo what I want: https://ibb.co/MnLQf6n照片我想要什么: 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.我需要将文本垂直对齐到桌面屏幕上的图像中心点。

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只需将 align-items-center 添加到行,它将使布局垂直居中 从此处了解 flex 并从此处引导 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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM