Lesson 7 / الدرس 7

Sizing: widths, heights and containers / التحجيم: العروض والارتفاعات والحاويات

How wide is a thing? Both frameworks answer with a mix of fractions, fixed steps and a container that centres your page — and the container is the first class most people learn.

كم عرض الشيء؟ يجيب الإطاران بمزيج من الكسور والدرجات الثابتة وحاوية تتوسّط صفحتك — والحاوية أول صنف يتعلمه معظم الناس.

Sizing splits into three questions that need different answers: how wide relative to the parent, how wide in absolute terms, and how wide at most. The CSS course covered all three; the frameworks give each a naming pattern.

You wantTailwindBootstrap
Full width of the parentw-fullw-100
Half the parentw-1/2w-50
A fixed stepw-64— use a utility or CSS
Never wider thanmax-w-md— use the grid
Full viewport heighth-screenvh-100
A centred page containercontainer mx-autocontainer

Note the gaps. Bootstrap has fewer sizing utilities because it expects you to reach for the grid instead, which is the next two lessons. Tailwind expects you to size things directly.

The container

BOOTSTRAP
  <div class="container">      centred, with a max width per breakpoint
  <div class="container-fluid"> always full width

TAILWIND
  <div class="container mx-auto px-4">
        note: Tailwind's container does NOT centre itself.
        mx-auto is doing that, and px-4 stops text touching the edge.
The Tailwind difference catches people: its container only sets a max width, so without mx-auto your page sits against the left edge. Run the demonstration to see a container doing its job.

Prefer a maximum to a fixed width

w-96 is 384px on every screen, including a 360px phone, where it overflows and produces the horizontal scrollbar the CSS course warned about. max-w-96 is 384px at most and narrower when there is less room. Almost every place you reach for a fixed width, the maximum is what you actually meant.

Two more that earn their place. aspect-video and aspect-square hold a shape while the width changes — the aspect-ratio lesson from the CSS course, as one class, and the right way to stop a video embed jumping as it loads. And w-fit sizes a box to its content, which is what you want for a button that should not stretch.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. Why does a Tailwind container not centre the page?

2. Why prefer max-w-96 over w-96?

3. Why avoid a fixed height on a box containing text?

Your task / مهمتك

Build the same three-part layout in both frameworks: a centred page container, a heading area, and a row of three boxes that are one half and two quarters wide. Then break it on purpose — give one box a fixed width and a fixed height, narrow the preview, and show what happens. Fix it and explain which class you changed and why.

ابنِ التخطيط الثلاثي نفسه في الإطارين: حاوية صفحة متوسّطة، ومنطقة عنوان، وصف من ثلاثة صناديق بعرض نصف وربعين. ثم اكسره عمدًا — أعطِ صندوقًا عرضًا ثابتًا وارتفاعًا ثابتًا، وضيّق المعاينة، وأظهر ما يحدث. وأصلحه واشرح أي صنف غيّرت ولماذا.

  • The same layout in both frameworks التخطيط نفسه في الإطارين
  • A centred container in each حاوية متوسّطة في كل واحد
  • The break shown, narrow, before the fix الكسر معروض ضيقًا قبل الإصلاح
  • The class you changed, and why الصنف الذي غيّرته ولماذا
How do you want to submit? / كيف تريد التسليم؟