Chapter 13CSS Tutorial~1 min read
CSS Flexbox
Flexible Box Layout — Modern Layouts
Flexbox म्हणजे Flexible Box Layout — एक modern CSS layout module जे responsive layouts बनवणे खूप सोपे करते. Floats आणि positioning hacks शिवाय alignment करता येते.
Flexbox सुरू करणे
Flex Container Setup
css
.container {
display: flex;
/* Container = flex container
Direct children = flex items */
}Marathi Analogy
📏 Analogy: Flexbox म्हणजे shelf organizer सारखे. Shelf (container) आहे, त्यावर items (flex items) आहेत. Shelf horizontal असेल किंवा vertical — items कसे align करायचे सगळे control करता येते.
Container Properties
Flex Container Properties
css
.container {
display: flex;
/* Direction — items कुठे जातील */
flex-direction: row; /* → left to right (default) */
flex-direction: row-reverse; /* ← right to left */
flex-direction: column; /* ↓ top to bottom */
flex-direction: column-reverse; /* ↑ bottom to top */
/* Wrap — items एकाच line मध्ये राहतात का? */
flex-wrap: nowrap; /* Default — एकाच line */
flex-wrap: wrap; /* पुढच्या line वर जातात */
/* Main axis alignment (horizontal जर row) */
justify-content: flex-start; /* डाव्या बाजूला */
justify-content: flex-end; /* उजव्या बाजूला */
justify-content: center; /* मध्यभागी */
justify-content: space-between; /* Items मध्ये समान space */
justify-content: space-around; /* Items भोवती समान space */
justify-content: space-evenly; /* सगळीकडे समान space */
/* Cross axis alignment (vertical जर row) */
align-items: stretch; /* Default — full height */
align-items: flex-start; /* वर */
align-items: flex-end; /* खाली */
align-items: center; /* मध्यभागी — centering साठी! */
}Perfect Center — Flexbox ने
css
/* Element पूर्णपणे center करणे — Flexbox ने सगळ्यात सोपे */
.container {
display: flex;
justify-content: center; /* Horizontal center */
align-items: center; /* Vertical center */
height: 100vh; /* Full screen height */
}Flex Item Properties
Flex Item Properties
css
.item {
/* flex-grow — available space किती घेतो */
flex-grow: 1; /* सगळी available space घेतो */
flex-grow: 0; /* Default — जेवढा content तेवढाच */
/* flex-shrink — container छोटा झाल्यावर किती shrink होतो */
flex-shrink: 1; /* Default — shrink होतो */
flex-shrink: 0; /* Shrink नाही */
/* align-self — individual item चे cross-axis alignment */
align-self: center;
align-self: flex-start;
}💡
Navbar, card grids, centering elements — सगळ्यासाठी Flexbox वापरतात. justify-content: space-between हे navigation links साठी सगळ्यात जास्त वापरले जाते.
✅ Key Points — लक्षात ठेवा
- ▸display: flex — container ला flex बनवतो, children flex items होतात
- ▸flex-direction: row/column — main axis direction
- ▸justify-content — main axis alignment (horizontal)
- ▸align-items — cross axis alignment (vertical)
- ▸Perfect center: justify-content: center + align-items: center
0/16 chapters पूर्ण