Modern Layout

๐ŸŽจ CSS3+ ๐ŸŸข Chapter 43 of 49 ๐Ÿ“‚ Phase 16: Modern CSS ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Grid ยท Flexbox ยท Container Queries ยท Subgrid ยท aspect-ratio ยท object-fit ยท Logical Properties ยท Writing Modes ยท min-content ยท max-content ยท fit-content
Welcome to Chapter 43: Modern Layout โ€” part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
๐Ÿ“š What You Will Learn
  • Modern layout toolkit: Flexbox + Grid + Container Queries together
  • subgrid for nested grid alignment across components
  • aspect-ratio, object-fit for responsive media
  • Logical properties (inline-size, margin-block) for internationalization
  • Intrinsic sizing: min-content, max-content, fit-content
๐Ÿ’ก Why This Matters

2020+ CSS layout is dramatically more powerful. aspect-ratio eliminates padding-hack for video embeds. Logical properties make RTL/LTR support trivial. subgrid solves the "nested grid alignment" problem that frustrated developers for years.

1aspect-ratio & object-fit
.video-wrapper {
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.video-wrapper iframe,
.video-wrapper video {
  width: 100%;
  height: 100%;
  border: none;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
}
Property / SelectorExplanation
aspect-ratio: 16/9Width set cheste height auto calculate โ€” no padding hack
object-fit: coverImage container fill chestundi, crop if needed
object-position: center topCrop focus point control
2Logical Properties โ€” RTL Ready Layouts
.card {
  /* Physical (old) */
  /* padding-left: 16px; margin-top: 24px; width: 300px; */

  /* Logical (modern) โ€” works for LTR and RTL */
  padding-inline-start: 16px;
  margin-block-start: 24px;
  inline-size: 300px;
  border-inline-start: 3px solid #2563eb;
}

[dir="rtl"] .card {
  /* No override needed โ€” logical properties auto-flip! */
}
3Subgrid & Intrinsic Sizing
.page-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.card-grid-item {
  display: grid;
  grid-template-rows: subgrid;
  grid-row: span 3;
}

.intrinsic-box {
  width: fit-content;
  max-width: min(100%, 65ch);
  min-width: min-content;
}

min-content: Shrink to smallest content width. max-content: Expand to full content without wrapping. fit-content: min(max-content, available space).

4Modern Layout Stack โ€” Practical Example
CSS โ€” Documentation Site Layoutโ–ถ Try in Editor
.docs-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.docs-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  container-type: inline-size;
}

.docs-content {
  padding: 40px clamp(16px, 5vw, 64px);
  max-inline-size: 75ch;
}

@container (max-width: 200px) {
  .sidebar-link span { display: none; }
}

@media (max-width: 768px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-sidebar { display: none; }
}
โœ… Quick Recap
  • aspect-ratio replaces padding-bottom percentage hack for embeds
  • Logical properties (inline/block) for international layouts
  • subgrid aligns nested grid items to parent grid tracks
  • fit-content, min-content, max-content for intrinsic sizing
  • Combine Grid (page) + Flexbox (components) + Container Queries (widgets)
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy ยท CSS Complete Roadmap ยท Last updated August 2026