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 want | Tailwind | Bootstrap |
|---|---|---|
| Full width of the parent | w-full | w-100 |
| Half the parent | w-1/2 | w-50 |
| A fixed step | w-64 | — use a utility or CSS |
| Never wider than | max-w-md | — use the grid |
| Full viewport height | h-screen | vh-100 |
| A centred page container | container mx-auto | container |
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.
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.
container عنده لا يضبط إلا عرضًا أقصى، فبدون mx-auto تجلس صفحتك ملاصقة للحافة اليسرى. شغّل العرض لترى حاوية تؤدي عملها.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.
w-96 هي 384 بكسل على كل شاشة، بما فيها هاتف بعرض 360، حيث تفيض وتنتج شريط التمرير الأفقي الذي حذّرت منه دورة CSS. وmax-w-96 هي 384 بكسل على الأكثر وأضيق حين تقل المساحة. وفي كل موضع تقريبًا تلجأ فيه إلى عرض ثابت، يكون الحد الأقصى هو ما قصدته فعلًا.h-32 تبدو صحيحة حتى يصير النص أطول بسطر، أو يكون خط القارئ أكبر، أو يمتد النص نفسه بالعربية إلى سطرين حيث امتد بالإنجليزية إلى سطر — فيُقتطع المحتوى أو يفيض. اضبط الحشو ودع الارتفاع يتبع. وإن احتجت أرضية لا سقفًا فعلًا، فـmin-h-32 هي الصنف الذي أردته.
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.
aspect-video وaspect-square يحفظان شكلًا بينما يتغير العرض — وهو درس نسبة الأبعاد من دورة CSS في صنف واحد، والطريقة الصحيحة لمنع قفز فيديو مضمّن أثناء تحميله. وw-fit يحجّم صندوقًا على محتواه، وهو ما تريده لزر لا ينبغي أن يتمدد.outline outline-1 outline-red-500 مؤقتًا إلى المشتبه به — أو استخدم طبقة التخطيط في أدوات المتصفح. فالعنصر الأعرض من أبيه هو دائمًا تقريبًا عرض ثابت، أو نص طويل بلا فواصل، أو صورة بلا max-w-full.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
Why does a Tailwind container not centre the page?
container في Tailwind الصفحة؟Bootstrap's container centres itself; Tailwind's does not. Forgetting mx-auto is why a first Tailwind page sits against the left edge.
mx-auto هو سبب جلوس أول صفحة Tailwind ملاصقة للحافة اليسرى.
2.
Why prefer max-w-96 over w-96?
max-w-96 على w-96؟A fixed 384px box on a 360px phone produces the horizontal scrollbar the CSS course warned about. The maximum is usually what you meant.
3. Why avoid a fixed height on a box containing text?
Set padding and let the height follow. min-h- is the class for when you genuinely need a floor.
min-h- هو الصنف حين تحتاج أرضية فعلًا.Score / النتيجة: 0 / 3
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 الصنف الذي غيّرته ولماذا