Color scheme

Subgrid, Container Queries, and Sticky

This assignment builds directly on the grid work you completed in the previous assignment. You will upgrade your existing card grid to use subgrid so card internals align across rows, add container query behavior to an existing component so it responds to its own context rather than the viewport, and implement a sticky module on one of your pages. When you are finished, all three features should be live on your portfolio.

Preparation

You will add a new unit-4/advanced/ directory with four files, edit your existing unit-4/grid-layouts/cards.css, and optionally touch your shared css/tokens/variables.css if you need a sticky offset token. The files you will create or modify are marked below:


        [portfolio]
        ├── css/
        │   └── tokens/
        │       └── variables.css       # May Update
        ├── unit-4/
        │   ├── grid-layouts/
        │   │   ├── cards.html
        │   │   └── cards.css           # Update: Add Subgrid
        │   └── advanced/
        │       ├── container-demo.html # New
        │       ├── container-demo.css  # New
        │       ├── sticky-demo.html    # New
        │       └── sticky-demo.css     # New
        ├── index.html                      # Update: Add Links
        └── README.md                       # Update: Pages Links
    

Create the unit-4/advanced/ directory and its four files before you begin. Each HTML file should link to your shared css/main.css for tokens and base styles, and to its own local stylesheet for the layout-specific CSS you write here.

The required live shared sheet is css/main.css. If you are keeping a bundler, follow After This Assignment: Stop or Keep.

Assignment Instructions

1. Upgrade the Card Grid with Subgrid

Open unit-4/grid-layouts/cards.css. Your card grid currently gives each card its own internal row tracks, so titles, body text, and footer buttons sit at different heights across a row when card content varies in length. Your job is to fix that by adding shared row tracks to the parent grid and opting each card into subgrid so it inherits those tracks rather than computing its own.

You will need to define three row tracks on the parent grid (one for the title zone, one for the body, one for the footer), make each card span all three of those tracks, and set grid-template-rows: subgrid on each card. Pay attention to align-items on the parent and row-gap: the reading explains why both matter here. When you are done, cards with very different title lengths should have body text and footer buttons that line up perfectly across the row.

Verify by temporarily giving two or three of your cards unusually long or short titles. The alignment should hold regardless of content length. Add an @supports guard so the layout remains readable in browsers that do not yet support subgrid.

2. Add a Container Query Component

Create unit-4/advanced/container-demo.html with a page that places the same component in two different layout contexts: one narrow (like a sidebar) and one wide (like a main content area). The component can be a card, a media object, a feature block, or any repeating UI pattern from your site.

In container-demo.css, establish a containment context on the wrapper of each placement using container-type, then write at least one @container rule that changes the component layout at a breakpoint you choose. The component should stack vertically in the narrow context and shift to a horizontal arrangement in the wide one, or some other meaningful layout change that makes sense for the component you picked.

The goal is a component that adapts to where it lives without any media query or JavaScript involved. Add a second @container rule at a different breakpoint if you want to practice a third state. Name your container with container-name if you want to query a specific ancestor rather than the nearest one.

Remember that container-type goes on the wrapper and @container rules target descendants inside it. The component itself cannot query its own container.

3. Implement a Sticky Module

Create unit-4/advanced/sticky-demo.html with a page long enough to scroll. Add a sticky element of your choosing: a section header that stays visible as its section scrolls past, a sidebar that locks in place, or a table of contents that follows the reader. Make sure you include the required offset property or sticky will silently do nothing.

Once it is working, deliberately introduce the overflow bug from the reading: add overflow: hidden to a wrapper ancestor, confirm that sticky breaks, then fix it. Leave a comment in your CSS at the location of the fix explaining what caused the problem and what you changed to resolve it. That comment is part of the submission.

Think carefully about your fix. Removing overflow: hidden entirely may break whatever visual effect it was providing. Is there a way to achieve the same visual result without applying overflow to the ancestor that sits between your sticky element and its scroll container?

4. Update Your Homepage and README

Add links to your container demo, sticky demo, and updated card grid on your portfolio homepage. Group them under a Unit 4 Advanced section or alongside your existing Unit 4 links, whichever fits your current homepage structure. Update your README.md under the Pages section with entries for each page, following the same markdown list pattern from previous assignments.

5. Commit and Verify

Push your changes to GitHub and confirm that the live site reflects all three features. Check each page on a real device or in a narrow browser window to make sure nothing breaks at small sizes.

Submission

Complete the report below. When you are finished, download the PDF and submit it to Canvas.

Subgrid and Container Layouts Report
Site Details

My live advanced layouts pages are at and the source code is at .

Reflection
Container Queries vs. Media Queries

You have now used both. Describe a situation where a container query was the right call and a situation where a media query is still the better tool. What is it about each context that makes one the correct choice over the other?

The Sticky Overflow Bug

A sticky element can silently stop working when an ancestor has overflow set to something other than visible. Explain what is actually happening at the browser level when this occurs, not just the symptom. If you hit this while building your sticky module, describe how you diagnosed and resolved it. If you did not, explain how you would track down the offending ancestor in a layout where sticky was failing.

Subgrid Tradeoffs

Subgrid solved the card alignment problem cleanly, but it is not free. Given its browser support, would you ship subgrid on a production site for a real client today? Defend your answer, and describe what your fallback strategy would be for browsers that do not support it.