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