flex-basis प्रॉपर्टी फ्लेक्स आइटम का प्रारंभिक मुख्य आकार (main size) निर्धारित करती है, इससे पहले कि flex-grow या flex-shrink लागू हों। यह width (row के लिए) या height (column के लिए) जैसा व्यवहार करता है लेकिन फ्लेक्स संदर्भ में।
उदाहरण: Q4 के लिए flex-basis: 350px
Q4 का प्रारंभिक आकार 350px सेट है, अन्य आइटम्स 100px हैं। अतिरिक्त स्थान होने पर flex-grow से वितरित होगा।
<!DOCTYPE html>
<html>
<head>
<style>
.mycontainer {
display: flex;
background-color: orange;
gap: 10px;
padding: 10px;
}
.mycontainer > div {
background-color: white;
text-align: center;
line-height: 40px;
font-size: 25px;
width: 100px;
flex-basis: 100px; /* डिफ़ॉल्ट बेसिस */
}
</style>
</head>
<body>
<h1>क्विज़</h1>
<div class="mycontainer">
<div>Q1</div>
<div>Q2</div>
<div>Q3</div>
<div style="flex-basis: 350px">Q4</div> <!-- बड़ा प्रारंभिक आकार -->
<div>Q5</div>
<div>Q6</div>
<div>Q7</div>
<div>Q8</div>
<div>Q9</div>
</div>
</body>
</html>
flex-basis मान
| मान | विवरण |
|---|---|
auto (डिफ़ॉल्ट) | आइटम के width/height या कंटेंट आकार का उपयोग करता है |
<length> | निश्चित आकार: 200px, 10rem, 50% |
content | कंटेंट आकार पर आधारित (कीवर्ड, सभी जगह सपोर्टेड नहीं) |
0 | शून्य बेसिस, केवल flex-grow से आकार |
flex-basis vs width
widthफ्लेक्स आइटम पर काम करता है लेकिन फ्लेक्स एल्गोरिदम द्वारा ओवरराइड हो सकता हैflex-basisफ्लेक्स एल्गोरिदम के लिए प्राथमिक इनपुट हैflex-basis: autoहोने परwidthउपयोग होता है
शॉर्टहैंड में उपयोग
/* flex: grow shrink basis */
flex: 1 1 300px; /* ग्रो, श्रिंक, 300px बेसिस */
flex: 0 0 200px; /* फिक्स्ड 200px, न ग्रो न श्रिंक */
flex: 1 1 auto; /* डिफ़ॉल्ट जैसा */
flex: 2 0 0; /* अनुपातिक वितरण, 0 बेसिस */
रिस्पॉन्सिव पैटर्न
.card {
flex: 1 1 300px; /* न्यूनतम 300px, फिर समान रूप से ग्रो */
}