[英]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.