flex-direction: column फ्लेक्स आइटम्स को मुख्य अक्ष (मेन एक्सिस) पर ऊपर से नीचे वर्टिकल रूप से व्यवस्थित करता है। क्रॉस एक्सिस हॉरिजॉन्टल हो जाता है।
उदाहरण: column दिशा में फ्लेक्स आइटम्स
<!DOCTYPE html>
<html>
<head>
<style>
.mycontainer {
display: flex;
flex-direction: column;
background-color: orange;
gap: 10px;
padding: 10px;
}
.mycontainer > div {
background-color: white;
text-align: center;
line-height: 40px;
font-size: 25px;
width: 100px;
align-self: center; /* हॉरिजॉन्टल केंद्र में */
}
</style>
</head>
<body>
<h1>क्विज़</h1>
<div class="mycontainer">
<div>Q1</div>
<div>Q2</div>
<div>Q3</div>
<div>Q4</div>
<div>Q5</div>
<div>Q6</div>
</div>
</body>
</html>
column vs column-reverse
| मान | प्रवाह दिशा | क्रॉस-स्टार्ट | क्रॉस-एंड |
|---|---|---|---|
column | ऊपर → नीचे | बाएं | दाएं |
column-reverse | नीचे → ऊपर | बाएं | दाएं |
कॉलम मोड में justify-content / align-items
- justify-content → वर्टिकल स्पेस वितरण (क्योंकि मेन एक्सिस वर्टिकल है)
- align-items → हॉरिजॉन्टल संरेखण (क्योंकि क्रॉस एक्सिस हॉरिजॉन्टल है)
.vertical-center {
display: flex;
flex-direction: column;
justify-content: center; /* वर्टिकल केंद्र */
align-items: center; /* हॉरिजॉन्टल केंद्र */
height: 100vh;
}
मोबाइल-फर्स्ट पैटर्न
.container {
display: flex;
flex-direction: column;
}
@media (min-width: 768px) {
.container {
flex-direction: row;
}
}