繁体   English   中英

"在块中显示时,如何使用 flex 在 Jumbotron 中垂直居中项目?"

[英]How do you vertically center items in Jumbotron using flex while displaying in block?

我试过这个将所有项目垂直居中在一个 Jumbotron 中,

display: flex;
justify-content: center;
align-items: center;

由于block元素垂直堆叠,将 flex 方向更改为column ,flex 项目也将如此。

display: flex;
flex-direction: column;              /*  added  */
justify-content: center;
align-items: center;

除了上面的答案,您还可以通过将 text-align 设置为居中来居中文本元素,例如h1<\/code> 、 p<\/code>或a<\/code> 。

display: flex;
flex-direction: column;              
justify-content: center;
align-items: center;                    /*  aligning items  */
text-align: center;                     /*  aligning text  */

暂无
暂无

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

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