简体   繁体   中英

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

I tried this to vertically center all items in a Jumbotron,

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

Since block element stacks vertically, change the flex direction to column , and so will the flex items.

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

Adding to above answer, you can also center text elements such as h1<\/code> , p<\/code> or a<\/code> by setting text-align to center.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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