CSS Flexbox لے آؤٹ جنریٹر

استعمال کا طریقہ 3 مراحل
  1. flex-direction، justify-content اور align-items طے کریں۔
  2. flex-wrap اور وقفہ طے کریں؛ پیش منظر ترتیب فوراً دکھاتا ہے۔
  3. Flexbox CSS کاپی کریں دبائیں اور اپنی اسٹائل شیٹ میں چسپاں کریں۔
خانہ 1
خانہ 2
خانہ 3
تیار کردہ Flexbox CSS

یہ ٹول کیسے کام کرتا ہے

Flexbox عناصر کو ایک محور کے ساتھ ترتیب دیتا ہے اور دوسرے محور پر انہیں سیدھ میں لاتا ہے۔ کون سا محور کون سا ہے، یہ پوری طرح flex-direction طے کرتا ہے: قطار میں مرکزی محور افقی چلتا ہے، اس لیے justify-content عناصر کو بائیں سے دائیں پھیلاتا ہے اور align-items انہیں عمودی طور پر رکھتا ہے۔ column پر جائیں تو دونوں آپس میں بدل جاتے ہیں۔ Flexbox میں الجھن کا تقریباً ہر لمحہ اسی تبدیلی سے آتا ہے۔

justify-content عناصر کو مرکزی محور پر تقسیم کرتا ہے، align-items انہیں اس کے آر پار رکھتا ہے، flex-wrap طے کرتا ہے کہ نہ سمانے والے عناصر نئی سطر پر جائیں یا دبا دیے جائیں، اور gap ان کے درمیان جگہ مقرر کرتا ہے۔ پیش منظر column کی حالت میں اونچائی لے لیتا ہے، کیونکہ ایسے ڈبے میں جو اپنے مواد جتنا ہی اونچا ہو، align-items کے پاس دکھانے کو کچھ نہیں ہوتا۔

کون سی خصوصیت کیا کرتی ہے

  • سمت بدلنے سے محور آپس میں بدل جاتے ہیں: justify-content قطار میں افقی ہے اور column میں عمودی۔ اگر کوئی خصوصیت آپ کی توقع کے مطابق کام کرنا چھوڑ دے تو سب سے پہلے سمت دیکھیں۔
  • gap نے بچوں پر لگے مارجن کی جگہ لے لی: ڈبے پر ایک اعلان، ہر عنصر پر مارجن کے بجائے، اور آگے پیچھے کوئی فالتو جگہ نہیں جسے ہٹانا پڑے۔ یہی وجہ ہے کہ flex خاکوں کو پہلے سے کہیں کم درستی درکار ہوتی ہے۔
  • nowrap طے شدہ ہے اور یہ دبا دیتا ہے: جو عناصر نہ سمائیں انہیں نئی سطر پر بھیجنے کے بجائے دبا دیا جاتا ہے۔ اگر کوئی قطار تنگ اسکرین پر اپنا مواد کچل رہی ہو تو wrap اس کا حل ہے۔
  • الٹی سمتیں ترتیب کو نظر میں بدلتی ہیں، دستاویز میں نہیں: کی بورڈ اور اسکرین ریڈر کی ترتیب مارک اپ کے مطابق چلتی ہے۔ صرف نظر کے لیے الٹنا ان دونوں کو آپس میں متضاد چھوڑ دیتا ہے، جو ماؤس کے بغیر چلنے والے ہر شخص کے لیے الجھن ہے۔

The axes swap, and that is the whole confusion

Flexbox lays items out along one axis and aligns them across the other. Which is which is decided entirely by flex-direction.

In a row, the main axis runs horizontally: justify-content spaces items left to right and align-items positions them vertically. Switch to a column and the two swap over — justify-content now runs down the page and align-items across it.

Nearly every moment of confusion with flexbox traces back to that swap. If a property has stopped doing what you expect, check the direction before anything else. Seeing it happen in the [msm_tool slug="flexbox-generator"] tends to fix it permanently in a way that reading about it does not.

The values worth knowing

justify-content distributes along the main axis. flex-start, center and flex-end are self-explanatory. The three that get confused:

  • space-between — no space at the ends, so the first and last items touch the edges. This is the one you want for a header with a logo on one side and navigation on the other.
  • space-around — each item gets equal space on both sides, so the outer gaps end up half the size of the inner ones. It looks slightly wrong and is rarely what anyone meant.
  • space-evenly — every gap is equal, including the outer ones. Usually what people reach for space-around expecting.

align-items positions across the other axis. stretch is the default and is why a row of cards with different content lengths all end up the same height — useful, and occasionally surprising. center is the one that makes vertical centring trivial, which was famously not the case before flexbox existed.

Centring, finally

justify-content: center and align-items: center together centre on both axes, regardless of direction. That pair is the answer to a problem that consumed an unreasonable amount of collective effort for about fifteen years.

One caveat: the container needs a height for vertical centring to have anywhere to happen. A flex container that is only as tall as its contents centres them in exactly the space they already occupy, which looks like nothing happened.

nowrap is the default, and it squeezes

Items that do not fit are compressed rather than moved to a new line. If a row is crushing its contents on a narrow screen, flex-wrap: wrap is the fix, and it is the single most common omission in flex layouts that break on mobile.

Worth knowing what wrapping changes: once items wrap, align-items applies within each line, and align-content controls how the lines themselves are distributed. That second property only does anything on a wrapped, multi-line container, which is why it appears to be broken when tried on a single line.

gap replaced margins

One declaration on the container instead of a margin on every child, with no leading or trailing space to strip off and no :last-child rule. It is the reason modern flex layouts need far less tidying than they used to, and it is supported everywhere current.

The reverse directions have an accessibility cost

row-reverse and column-reverse change the order items appear in visually. They do not change the order in the document, which is what keyboard navigation and screen readers follow.

Reversing for visual effect leaves those two disagreeing: someone tabbing through the page moves in an order that does not match what they see. The same applies to the order property. Use them where the visual and document order genuinely should differ and you have thought about it — not as a quick way to move something to the right.

flex-grow, flex-shrink and flex-basis

These sit on the children rather than the container, and the shorthand catches people out. flex: 1 means grow to fill, do not resist shrinking, and start from zero — which is why flex: 1 on several items makes them equal width regardless of their content.

If you want items sized by their content but allowed to grow, flex: 1 1 auto is the form. The difference between a basis of 0 and auto accounts for most of the surprise when items come out a different size than expected.

Flexbox or grid

Use flexbox when the content decides the sizes: a navigation bar, a row of buttons, a card's internal layout. Use grid when the layout is defined before the content: a page skeleton, a gallery of equal tiles, anything two-dimensional.

They nest happily and most real pages use both — a grid for the page, flexbox inside each card.

اکثر پوچھے گئے سوالات

خاص طور پر CSS Flexbox لے آؤٹ جنریٹر کے بارے میں۔ اس زمرے سے متعلق عمومی سوالات کے جواب زمرے کے صفحے پر موجود ہیں۔

سمت column پر لگی ہے، جو محور بدل دیتی ہے۔ column میں justify-content صفحے پر نیچے کی طرف چلتا ہے اور align-items آر پار۔
justify-content: center اور align-items: center ایک ساتھ۔ یہ جوڑا دونوں محوروں پر درمیان میں لاتا ہے، سمت کوئی بھی ہو۔
space-between سروں پر کوئی جگہ نہیں چھوڑتا، اس لیے پہلا اور آخری عنصر کناروں سے لگ جاتے ہیں۔ space-evenly ہر وقفہ برابر رکھتا ہے، بیرونی وقفے بھی۔
flex-wrap طے شدہ طور پر nowrap ہوتا ہے، جو عناصر کو سمانے کے لیے دبا دیتا ہے۔ اسے wrap پر رکھیں تاکہ وہ نئی سطر پر چلے جائیں۔
ایک ہی قطار یا کالم کے لیے flexbox، جہاں سائز مواد طے کرے۔ Grid تب جب آپ کو ایک ساتھ سطریں اور کالم چاہیے ہوں، یا خاکہ مواد جاننے سے پہلے متعین ہو۔

نئے ٹولز، خصوصیات اور کارکردگی بڑھانے کے مشوروں کی اطلاع پانے کے لیے سبسکرائب کریں۔