Flex Items
๐ Covered in this chapter:
flex-grow ยท flex-shrink ยท flex-basis ยท flex shorthand ยท align-self ยท order ยท Flexible Cards ยท Equal Height ยท Centering ยท Wrapping ยท Common Mistakes ยท Debugging
Welcome to Chapter 22: Flex Items โ part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1flex-grow, flex-shrink, flex-basis
.sidebar { flex: 0 0 240px; } /* don't grow, don't shrink, 240px basis */
.main { flex: 1 1 auto; } /* grow to fill remaining space */
.card { flex: 1 1 300px; } /* flexible cards, min ~300px */
flex: 1 shorthand = flex: 1 1 0% โ equal distribution.
2align-self, order & Centering
CSS โ Perfect Center
.center-box {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.item-first { order: -1; }
.item-center { align-self: center; }
3Equal-Height Layouts & Common Mistakes
โ ๏ธ Common Flex Mistakes
align-items: centeron parent โ children stretch avvavu, equal height lost- Forgetting
min-width: 0on flex children โ text overflow issues - Using margins instead of
gapfor spacing orderabuse โ visual order DOM order nundi different, accessibility problem