简体   繁体   English

bootstrap 4 中列的垂直对齐

[英]Vertical alignment of columns in bootstrap 4

I've searched on google and this site for answers on how to vertically align columns to be centered.我在谷歌和这个网站上搜索过关于如何垂直对齐列以使其居中的答案。 I've found entries with this exact title but none of them work, they all show how to align horizontally.我找到了具有这个确切标题的条目,但它们都不起作用,它们都显示了如何水平对齐。 Even the bootply's etc. links to examples which centers horizontally and not vertically.甚至 bootply 的等链接到水平居中而不是垂直居中的示例。

I've followed the guide on bootstraps official site, and it is telling me to just use the class align-items-center on the row, or adding align-content-center on the column, but these doesn't work for me at all, I get no response.我遵循了 bootstraps 官方网站上的指南,它告诉我只在行上使用类 align-items-center,或在列上添加 align-content-center,但这些对我不起作用所有,我没有得到任何回应。

Can someone tell me what I am doing wrong here?有人可以告诉我我在这里做错了什么吗?

This is the guide I used: http://getbootstrap.com/docs/4.0/layout/grid/#alignment这是我使用的指南: http : //getbootstrap.com/docs/4.0/layout/grid/#alignment

And I am using the latest bootstrap v4.0.0.beta-2.我正在使用最新的引导程序 v4.0.0.beta-2。

Example from my code:我的代码中的示例:

<div class="container">
  <div class="row align-items-center">
    <div class="col-3"><span>test</span></div>
  </div>
</div>

Expected result: Column with the text "test" should be located vertically centered on my page.预期结果:带有文本“test”的列应位于我页面的垂直居中位置。

Actual result: Text is showing in the left upper corner of the page.实际结果:文本显示在页面的左上角。

Bootstrap row will contain flex property. Bootstrap 行将包含 flex 属性。 With that only we can able to use flex properties for child divs.只有这样我们才能为子 div 使用 flex 属性。 But here in your example you haven't used row class or d-flex class in your code.但是在您的示例中,您没有在代码中使用 row 类或 d-flex 类。

I suggest you to add row into your code..我建议您在代码中添加行..

<div class="container">
  <div class="row align-items-center">
    <div class="col-3"><span>test</span></div>
  </div>
</div>

Now your code will center the text vertically, But within the container height.现在您的代码将垂直居中文本,但在容器高度内。 It won't be center to your html page.它不会以您的 html 页面为中心。

Vertical Center: JS Fiddle垂直中心: JS Fiddle

To make Your text to center of your page, make row div to full height 100vh要使您的文本位于页面中心,请将行 div 设为全高 100vh

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

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