🎓 EASYTUTORGUIDE

Practical tutorials, tools, courses, digital skills, and business promotion.

★ Free Learning
Translate this lesson:
Arabic and Persian use RTL layout. CSS and HTML code remain LTR. Long translated text wraps on all device sizes.

CSS • Chapter 33 • Foundations to Production

Grid Foundations

Every topic includes a CSS/HTML coding example, ten focused teaching examples, code explanation, expected result, practice, and responsive/translated-layout checks.

5 topics5 coding examples50 teaching examples10 Q&A
Estimated reading time0% read

33.1 display grid

display grid is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.

For display grid in Chapter 33, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.

Start with one small example for display grid, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 33, topic 1.

Concept in plain language

display grid is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.

10 teaching examples

  1. Example 1: Smallest useful case

    Build a minimal contact form for display grid. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 33, topic 1, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the button group example for display grid. Predict the visual difference before reloading the page. Chapter 33, topic 1, example 2.

  3. Example 3: Narrow-screen test

    Test display grid in the data table at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 33, topic 1, example 3.

  4. Example 4: Translated-text test

    Translate the media player into a language with longer labels while using display grid. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 33, topic 1, example 4.

  5. Example 5: Arabic/Persian test

    Switch the notification to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 33, topic 1, example 5.

  6. Example 6: Accessibility test

    Check display grid in the language selector with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 33, topic 1, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the course card and determine why the declaration for display grid wins or loses using the browser's Styles and Computed panels. Chapter 33, topic 1, example 7.

  8. Example 8: Content-stress test

    Fill the navigation bar with very long words, URLs, translated text, images, and nested controls. Adjust display grid without hiding meaningful content. Chapter 33, topic 1, example 8.

  9. Example 9: Refactoring test

    Rewrite the article so display grid uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 33, topic 1, example 9.

  10. Example 10: Production review

    Review display grid in the profile panel for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 33, topic 1, example 10.

CSS/HTML coding example

<!-- HTML -->
<h2>Balanced heading</h2>

<style>
:is(h1,h2,h3) { text-wrap: balance; }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate display grid.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. :is() groups selector alternatives without repeating the rest of the selector.
  4. Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
  5. Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.

Expected result: The browser visibly demonstrates display grid without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 33, topic 1.

Practice exercise

Build a fresh example for display grid from Chapter 33. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.

33.2 grid-template-columns

grid-template-columns is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.

For grid-template-columns in Chapter 33, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.

Start with one small example for grid-template-columns, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 33, topic 2.

Concept in plain language

grid-template-columns is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.

10 teaching examples

  1. Example 1: Smallest useful case

    Build a minimal media player for grid-template-columns. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 33, topic 2, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the notification example for grid-template-columns. Predict the visual difference before reloading the page. Chapter 33, topic 2, example 2.

  3. Example 3: Narrow-screen test

    Test grid-template-columns in the language selector at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 33, topic 2, example 3.

  4. Example 4: Translated-text test

    Translate the course card into a language with longer labels while using grid-template-columns. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 33, topic 2, example 4.

  5. Example 5: Arabic/Persian test

    Switch the navigation bar to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 33, topic 2, example 5.

  6. Example 6: Accessibility test

    Check grid-template-columns in the article with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 33, topic 2, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the profile panel and determine why the declaration for grid-template-columns wins or loses using the browser's Styles and Computed panels. Chapter 33, topic 2, example 7.

  8. Example 8: Content-stress test

    Fill the search form with very long words, URLs, translated text, images, and nested controls. Adjust grid-template-columns without hiding meaningful content. Chapter 33, topic 2, example 8.

  9. Example 9: Refactoring test

    Rewrite the dashboard so grid-template-columns uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 33, topic 2, example 9.

  10. Example 10: Production review

    Review grid-template-columns in the photo gallery for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 33, topic 2, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="grid"><aside>Menu</aside><main>Content</main></div>

<style>
.grid { display:grid; grid-template-columns:12rem minmax(0,1fr); }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate grid-template-columns.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. minmax(0,1fr) lets the content track shrink rather than forcing overflow.
  4. Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
  5. Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.

Expected result: The browser visibly demonstrates grid-template-columns without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 33, topic 2.

Practice exercise

Build a fresh example for grid-template-columns from Chapter 33. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.

33.3 grid-template-rows

grid-template-rows is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.

For grid-template-rows in Chapter 33, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.

Start with one small example for grid-template-rows, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 33, topic 3.

Concept in plain language

grid-template-rows is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.

10 teaching examples

  1. Example 1: Smallest useful case

    Build a minimal course card for grid-template-rows. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 33, topic 3, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the navigation bar example for grid-template-rows. Predict the visual difference before reloading the page. Chapter 33, topic 3, example 2.

  3. Example 3: Narrow-screen test

    Test grid-template-rows in the article at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 33, topic 3, example 3.

  4. Example 4: Translated-text test

    Translate the profile panel into a language with longer labels while using grid-template-rows. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 33, topic 3, example 4.

  5. Example 5: Arabic/Persian test

    Switch the search form to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 33, topic 3, example 5.

  6. Example 6: Accessibility test

    Check grid-template-rows in the dashboard with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 33, topic 3, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the photo gallery and determine why the declaration for grid-template-rows wins or loses using the browser's Styles and Computed panels. Chapter 33, topic 3, example 7.

  8. Example 8: Content-stress test

    Fill the pricing table with very long words, URLs, translated text, images, and nested controls. Adjust grid-template-rows without hiding meaningful content. Chapter 33, topic 3, example 8.

  9. Example 9: Refactoring test

    Rewrite the lesson sidebar so grid-template-rows uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 33, topic 3, example 9.

  10. Example 10: Production review

    Review grid-template-rows in the contact form for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 33, topic 3, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="grid"><header>Head</header><main>Main</main><footer>Foot</footer></div>

<style>
.grid { display:grid; grid-template-rows:auto 1fr auto; min-height:60dvh; }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate grid-template-rows.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. Grid rows can combine content-sized and flexible tracks.
  4. Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
  5. Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.

Expected result: The browser visibly demonstrates grid-template-rows without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 33, topic 3.

Practice exercise

Build a fresh example for grid-template-rows from Chapter 33. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.

33.4 gap

gap is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.

For gap in Chapter 33, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.

Start with one small example for gap, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 33, topic 4.

Concept in plain language

gap is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.

10 teaching examples

  1. Example 1: Smallest useful case

    Build a minimal profile panel for gap. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 33, topic 4, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the search form example for gap. Predict the visual difference before reloading the page. Chapter 33, topic 4, example 2.

  3. Example 3: Narrow-screen test

    Test gap in the dashboard at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 33, topic 4, example 3.

  4. Example 4: Translated-text test

    Translate the photo gallery into a language with longer labels while using gap. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 33, topic 4, example 4.

  5. Example 5: Arabic/Persian test

    Switch the pricing table to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 33, topic 4, example 5.

  6. Example 6: Accessibility test

    Check gap in the lesson sidebar with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 33, topic 4, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the contact form and determine why the declaration for gap wins or loses using the browser's Styles and Computed panels. Chapter 33, topic 4, example 7.

  8. Example 8: Content-stress test

    Fill the button group with very long words, URLs, translated text, images, and nested controls. Adjust gap without hiding meaningful content. Chapter 33, topic 4, example 8.

  9. Example 9: Refactoring test

    Rewrite the data table so gap uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 33, topic 4, example 9.

  10. Example 10: Production review

    Review gap in the media player for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 33, topic 4, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="grid"><div>A</div><div>B</div></div>

<style>
.grid { display:grid; gap:clamp(.75rem,2vw,1.5rem); }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate gap.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. gap adds spacing between grid or flex tracks without edge margins.
  4. Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
  5. Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.

Expected result: The browser visibly demonstrates gap without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 33, topic 4.

Practice exercise

Build a fresh example for gap from Chapter 33. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.

33.5 Grid Placement

Grid Placement is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.

For Grid Placement in Chapter 33, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.

Start with one small example for Grid Placement, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 33, topic 5.

Concept in plain language

Grid Placement is part of the CSS system covered in Chapter 33. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.

10 teaching examples

  1. Example 1: Smallest useful case

    Build a minimal photo gallery for Grid Placement. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 33, topic 5, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the pricing table example for Grid Placement. Predict the visual difference before reloading the page. Chapter 33, topic 5, example 2.

  3. Example 3: Narrow-screen test

    Test Grid Placement in the lesson sidebar at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 33, topic 5, example 3.

  4. Example 4: Translated-text test

    Translate the contact form into a language with longer labels while using Grid Placement. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 33, topic 5, example 4.

  5. Example 5: Arabic/Persian test

    Switch the button group to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 33, topic 5, example 5.

  6. Example 6: Accessibility test

    Check Grid Placement in the data table with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 33, topic 5, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the media player and determine why the declaration for Grid Placement wins or loses using the browser's Styles and Computed panels. Chapter 33, topic 5, example 7.

  8. Example 8: Content-stress test

    Fill the notification with very long words, URLs, translated text, images, and nested controls. Adjust Grid Placement without hiding meaningful content. Chapter 33, topic 5, example 8.

  9. Example 9: Refactoring test

    Rewrite the language selector so Grid Placement uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 33, topic 5, example 9.

  10. Example 10: Production review

    Review Grid Placement in the course card for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 33, topic 5, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo grid-placement">CSS topic: Grid Placement</div>

<style>
.grid-placement {
  padding: 1rem;
  border: 1px solid #94a3b8;
}
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Grid Placement.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Grid Placement, and the declaration changes a visible part of its presentation.
  4. Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
  5. Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.

Expected result: The browser visibly demonstrates Grid Placement without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 33, topic 5.

Practice exercise

Build a fresh example for Grid Placement from Chapter 33. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.

Chapter 33 review — 10 questions and answers

1. What should you inspect first when display grid does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for display grid. Then reduce the example until the winning declaration is clear.

2. How should display grid be checked before publishing?

Answer: Test display grid on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.

3. What should you inspect first when grid-template-columns does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for grid-template-columns. Then reduce the example until the winning declaration is clear.

4. How should grid-template-columns be checked before publishing?

Answer: Test grid-template-columns on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.

5. What should you inspect first when grid-template-rows does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for grid-template-rows. Then reduce the example until the winning declaration is clear.

6. How should grid-template-rows be checked before publishing?

Answer: Test grid-template-rows on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.

7. What should you inspect first when gap does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for gap. Then reduce the example until the winning declaration is clear.

8. How should gap be checked before publishing?

Answer: Test gap on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.

9. What should you inspect first when Grid Placement does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Grid Placement. Then reduce the example until the winning declaration is clear.

10. How should Grid Placement be checked before publishing?

Answer: Test Grid Placement on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.