简体   繁体   中英

how to center blocks after flex-wrap?

After flex-wrap wraps the block to the next line, I need to center it, but I can't. How to center the third block? Here is an example from the codepen where I can't

.block3 {
    align-self: center;
}

Codepen

You could opt for justify-content: space-between; :

 .head { display: flex; flex-wrap: wrap; justify-content: space-around; gap: 10px; }.block { display: flex; justify-content: center; align-items: center; width: 200px; height: 200px; background-color: red; }
 <div class="head"> <div class="block">1</div> <div class="block">2</div> <div class="block">3</div> </div>

I've also added in a gap: 10px to ensure that the blocks never touch when next to each other or when wrapping.

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