flex-direction प्रॉपर्टी फ्लेक्स कंटेनर के मेन एक्सिस (मुख्य अक्ष) को परिभाषित करती है, जिससे फ्लेक्स आइटम्स की दिशा निर्धारित होती है।
उदाहरण: वर्टिकल (कॉलम) दिशा
flex-direction: 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;
margin: 5px;
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>
flex-direction के सभी मान
| मान | दिशा | मेन एक्सिस |
|---|---|---|
row | बाएं से दाएं (डिफ़ॉल्ट) | हॉरिजॉन्टल |
row-reverse | दाएं से बाएं | हॉरिजॉन्टल |
column | ऊपर से नीचे | वर्टिकल |
column-reverse | नीचे से ऊपर | वर्टिकल |
रिस्पॉन्सिव दिशा परिवर्तन
.container {
display: flex;
flex-direction: column; /* मोबाइल पर वर्टिकल */
}
@media (min-width: 768px) {
.container {
flex-direction: row; /* डेस्कटॉप पर हॉरिजॉन्टल */
}
}
शॉर्टहैंड: flex-flow
flex-flow: column wrap; /* flex-direction + flex-wrap */