CSS • Chapter 17 • Foundations to Production
Stacking and Z-Index
Every topic includes a CSS/HTML coding example, ten focused teaching examples, code explanation, expected result, practice, and responsive/translated-layout checks.
17.1 Stacking Contexts
Stacking Contexts is part of the CSS system covered in Chapter 17. 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 Stacking Contexts in Chapter 17, 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 Stacking Contexts, 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 17, topic 1.
Concept in plain language
Stacking Contexts is part of the CSS system covered in Chapter 17. 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
Example 1: Smallest useful case
Build a minimal article for Stacking Contexts. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 17, topic 1, example 1.
Example 2: Change one value
Change one important CSS value in the profile panel example for Stacking Contexts. Predict the visual difference before reloading the page. Chapter 17, topic 1, example 2.
Example 3: Narrow-screen test
Test Stacking Contexts in the search form at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 17, topic 1, example 3.
Example 4: Translated-text test
Translate the dashboard into a language with longer labels while using Stacking Contexts. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 17, topic 1, example 4.
Example 5: Arabic/Persian test
Switch the photo gallery to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 17, topic 1, example 5.
Example 6: Accessibility test
Check Stacking Contexts in the pricing table with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 17, topic 1, example 6.
Example 7: Cascade test
Add a competing rule to the lesson sidebar and determine why the declaration for Stacking Contexts wins or loses using the browser's Styles and Computed panels. Chapter 17, topic 1, example 7.
Example 8: Content-stress test
Fill the contact form with very long words, URLs, translated text, images, and nested controls. Adjust Stacking Contexts without hiding meaningful content. Chapter 17, topic 1, example 8.
Example 9: Refactoring test
Rewrite the button group so Stacking Contexts uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 17, topic 1, example 9.
Example 10: Production review
Review Stacking Contexts in the data table for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 17, topic 1, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="demo stacking-contexts">CSS topic: Stacking Contexts</div>
<style>
.stacking-contexts {
padding: 1rem;
border: 1px solid #94a3b8;
}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Stacking Contexts.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The selector targets the demonstration for Stacking Contexts, and the declaration changes a visible part of its presentation.
- 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.
- 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 Stacking Contexts 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 17, topic 1.
Practice exercise
Build a fresh example for Stacking Contexts from Chapter 17. 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.
17.2 z-index
z-index is part of the CSS system covered in Chapter 17. 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 z-index in Chapter 17, 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 z-index, 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 17, topic 2.
Concept in plain language
z-index is part of the CSS system covered in Chapter 17. 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
Example 1: Smallest useful case
Build a minimal dashboard for z-index. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 17, topic 2, example 1.
Example 2: Change one value
Change one important CSS value in the photo gallery example for z-index. Predict the visual difference before reloading the page. Chapter 17, topic 2, example 2.
Example 3: Narrow-screen test
Test z-index in the pricing table at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 17, topic 2, example 3.
Example 4: Translated-text test
Translate the lesson sidebar into a language with longer labels while using z-index. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 17, topic 2, example 4.
Example 5: Arabic/Persian test
Switch the contact form to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 17, topic 2, example 5.
Example 6: Accessibility test
Check z-index in the button group with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 17, topic 2, example 6.
Example 7: Cascade test
Add a competing rule to the data table and determine why the declaration for z-index wins or loses using the browser's Styles and Computed panels. Chapter 17, topic 2, example 7.
Example 8: Content-stress test
Fill the media player with very long words, URLs, translated text, images, and nested controls. Adjust z-index without hiding meaningful content. Chapter 17, topic 2, example 8.
Example 9: Refactoring test
Rewrite the notification so z-index uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 17, topic 2, example 9.
Example 10: Production review
Review z-index in the language selector for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 17, topic 2, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="demo z-index">CSS topic: z-index</div>
<style>
.z-index {
padding: 1rem;
border: 1px solid #94a3b8;
}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate z-index.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The selector targets the demonstration for z-index, and the declaration changes a visible part of its presentation.
- 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.
- 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 z-index 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 17, topic 2.
Practice exercise
Build a fresh example for z-index from Chapter 17. 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.
17.3 Positioned Stacking
Positioned Stacking is part of the CSS system covered in Chapter 17. 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 Positioned Stacking in Chapter 17, 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 Positioned Stacking, 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 17, topic 3.
Concept in plain language
Positioned Stacking is part of the CSS system covered in Chapter 17. 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
Example 1: Smallest useful case
Build a minimal lesson sidebar for Positioned Stacking. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 17, topic 3, example 1.
Example 2: Change one value
Change one important CSS value in the contact form example for Positioned Stacking. Predict the visual difference before reloading the page. Chapter 17, topic 3, example 2.
Example 3: Narrow-screen test
Test Positioned Stacking in the button group at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 17, topic 3, example 3.
Example 4: Translated-text test
Translate the data table into a language with longer labels while using Positioned Stacking. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 17, topic 3, example 4.
Example 5: Arabic/Persian test
Switch the media player to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 17, topic 3, example 5.
Example 6: Accessibility test
Check Positioned Stacking in the notification with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 17, topic 3, example 6.
Example 7: Cascade test
Add a competing rule to the language selector and determine why the declaration for Positioned Stacking wins or loses using the browser's Styles and Computed panels. Chapter 17, topic 3, example 7.
Example 8: Content-stress test
Fill the course card with very long words, URLs, translated text, images, and nested controls. Adjust Positioned Stacking without hiding meaningful content. Chapter 17, topic 3, example 8.
Example 9: Refactoring test
Rewrite the navigation bar so Positioned Stacking uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 17, topic 3, example 9.
Example 10: Production review
Review Positioned Stacking in the article for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 17, topic 3, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="demo positioned-stacking">CSS topic: Positioned Stacking</div>
<style>
.positioned-stacking {
padding: 1rem;
border: 1px solid #94a3b8;
}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Positioned Stacking.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The selector targets the demonstration for Positioned Stacking, and the declaration changes a visible part of its presentation.
- 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.
- 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 Positioned Stacking 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 17, topic 3.
Practice exercise
Build a fresh example for Positioned Stacking from Chapter 17. 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.
17.4 Opacity and Stacking
Opacity and Stacking is part of the CSS system covered in Chapter 17. 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 Opacity and Stacking in Chapter 17, 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 Opacity and Stacking, 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 17, topic 4.
Concept in plain language
Opacity and Stacking is part of the CSS system covered in Chapter 17. 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
Example 1: Smallest useful case
Build a minimal data table for Opacity and Stacking. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 17, topic 4, example 1.
Example 2: Change one value
Change one important CSS value in the media player example for Opacity and Stacking. Predict the visual difference before reloading the page. Chapter 17, topic 4, example 2.
Example 3: Narrow-screen test
Test Opacity and Stacking in the notification at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 17, topic 4, example 3.
Example 4: Translated-text test
Translate the language selector into a language with longer labels while using Opacity and Stacking. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 17, topic 4, example 4.
Example 5: Arabic/Persian test
Switch the course card to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 17, topic 4, example 5.
Example 6: Accessibility test
Check Opacity and Stacking in the navigation bar with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 17, topic 4, example 6.
Example 7: Cascade test
Add a competing rule to the article and determine why the declaration for Opacity and Stacking wins or loses using the browser's Styles and Computed panels. Chapter 17, topic 4, example 7.
Example 8: Content-stress test
Fill the profile panel with very long words, URLs, translated text, images, and nested controls. Adjust Opacity and Stacking without hiding meaningful content. Chapter 17, topic 4, example 8.
Example 9: Refactoring test
Rewrite the search form so Opacity and Stacking uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 17, topic 4, example 9.
Example 10: Production review
Review Opacity and Stacking in the dashboard for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 17, topic 4, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="demo opacity-and-stacking">CSS topic: Opacity and Stacking</div>
<style>
.opacity-and-stacking {
padding: 1rem;
border: 1px solid #94a3b8;
}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Opacity and Stacking.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The selector targets the demonstration for Opacity and Stacking, and the declaration changes a visible part of its presentation.
- 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.
- 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 Opacity and Stacking 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 17, topic 4.
Practice exercise
Build a fresh example for Opacity and Stacking from Chapter 17. 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.
17.5 Debugging Overlapping Layers
Debugging Overlapping Layers is part of the CSS system covered in Chapter 17. 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 Debugging Overlapping Layers in Chapter 17, 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 Debugging Overlapping Layers, 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 17, topic 5.
Concept in plain language
Debugging Overlapping Layers is part of the CSS system covered in Chapter 17. 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
Example 1: Smallest useful case
Build a minimal language selector for Debugging Overlapping Layers. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 17, topic 5, example 1.
Example 2: Change one value
Change one important CSS value in the course card example for Debugging Overlapping Layers. Predict the visual difference before reloading the page. Chapter 17, topic 5, example 2.
Example 3: Narrow-screen test
Test Debugging Overlapping Layers in the navigation bar at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 17, topic 5, example 3.
Example 4: Translated-text test
Translate the article into a language with longer labels while using Debugging Overlapping Layers. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 17, topic 5, example 4.
Example 5: Arabic/Persian test
Switch the profile panel to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 17, topic 5, example 5.
Example 6: Accessibility test
Check Debugging Overlapping Layers in the search form with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 17, topic 5, example 6.
Example 7: Cascade test
Add a competing rule to the dashboard and determine why the declaration for Debugging Overlapping Layers wins or loses using the browser's Styles and Computed panels. Chapter 17, topic 5, example 7.
Example 8: Content-stress test
Fill the photo gallery with very long words, URLs, translated text, images, and nested controls. Adjust Debugging Overlapping Layers without hiding meaningful content. Chapter 17, topic 5, example 8.
Example 9: Refactoring test
Rewrite the pricing table so Debugging Overlapping Layers uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 17, topic 5, example 9.
Example 10: Production review
Review Debugging Overlapping Layers in the lesson sidebar for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 17, topic 5, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="demo debugging-overlapping-layers">CSS topic: Debugging Overlapping Layers</div>
<style>
.debugging-overlapping-layers {
padding: 1rem;
border: 1px solid #94a3b8;
}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Debugging Overlapping Layers.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The selector targets the demonstration for Debugging Overlapping Layers, and the declaration changes a visible part of its presentation.
- 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.
- 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 Debugging Overlapping Layers 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 17, topic 5.
Practice exercise
Build a fresh example for Debugging Overlapping Layers from Chapter 17. 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 17 review — 10 questions and answers
1. What should you inspect first when Stacking Contexts does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Stacking Contexts. Then reduce the example until the winning declaration is clear.
2. How should Stacking Contexts be checked before publishing?
Answer: Test Stacking Contexts 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 z-index does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for z-index. Then reduce the example until the winning declaration is clear.
4. How should z-index be checked before publishing?
Answer: Test z-index 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 Positioned Stacking does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Positioned Stacking. Then reduce the example until the winning declaration is clear.
6. How should Positioned Stacking be checked before publishing?
Answer: Test Positioned Stacking 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 Opacity and Stacking does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Opacity and Stacking. Then reduce the example until the winning declaration is clear.
8. How should Opacity and Stacking be checked before publishing?
Answer: Test Opacity and Stacking 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 Debugging Overlapping Layers does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Debugging Overlapping Layers. Then reduce the example until the winning declaration is clear.
10. How should Debugging Overlapping Layers be checked before publishing?
Answer: Test Debugging Overlapping Layers 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.