Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Inspect What a Subgrid Inherits

In this lesson, you tested what Rosa’s pool cards take from the pool list’s grid, one DevTools experiment at a time, with the Grid overlay on and the device toolbar at 1280 pixels. DevTools edits last only until the page reloads, so your files don’t change.

Key Points

  • A subgrid gets exactly the tracks its item spans in the parent grid. Each pool card spans three rows, so its subgrid has three rows.
  • Only the subgrid’s own children sit on those tracks. A badge isn’t the card’s child but its grandchild, so grid-row: 1 on the badges moves nothing. Their parent, the badge list, is a flex container that lays them out on its own.
  • Line names come down with the tracks. In [name] auto [times] auto [badges] auto, each name in brackets names the line that starts the row after it, and auto is that row’s size. A card defines no names of its own, yet grid-row: name places its badges at the list’s line called name. The name and times, with no row set, then fill the free rows after it, in order.
  • The gap comes down too. The card sets no gap, yet the space between its name and its times is the list’s 18-pixel row gap. A row-gap on the card overrides it inside every card. With --space-control-block, the small space the badges use between them, the gap drops to 9 pixels.
  • In its subgridded direction, a subgrid adds no tracks. A fourth child in a card that spans three rows finds no free row left, so it shares the last one, on top of the badges. This short note doesn’t make the card grow. Longer text would make that shared row taller, but never add a fourth.
  • When you write a subgrid, count the tracks the item spans and its children. More children than tracks, and the extras share the last one.

The Experiments

Each of these was added in the Styles pane, not in styles.css:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Rosa’s pool cards now line up. In the Grid overlay, the list has three rows, and every card’s name, opening times and lane badges sit in them. That took a span of three rows.

00:12 Without it, each card’s subgrid had one track, and all three parts piled up in it.

00:19 So the span decides how many rows a card gets. In this video, you’ll test what else a card takes from the list’s grid, one experiment at a time in DevTools.

00:29 Each edit lasts until the page reloads, so your files don’t change.

00:35 First, the badges. Each badge is a list item inside the card’s badge list, so it’s the card’s grandchild. In the Styles pane, give the badges’ rule a grid row of one.

00:47 Nothing moves. A badge isn’t the card’s child, so it isn’t placed on the card’s rows. Its parent, the badge list, is a flex container that lays it out on its own.

00:59 Only the card’s own children sit on the shared rows.

01:04 Next, line names. On the list’s rule, name its lines: name, times and badges. Each name in brackets names the line that starts the row after it, and auto is that row’s size.

01:17 Then turn on line names in the Layout pane. The card defines no names of its own. So place the badges at the line called name. In every card, the badges jump to the top row.

01:30 The name and times have no row set, so they fill the free rows after it, in order. The card found the list’s names, because a subgrid inherits them with its tracks.

01:41 Untick the test, and the badges drop back.

01:46 Look at the space between a card’s name and its times. It’s 18 pixels, but the card’s rule sets no gap. It’s the list’s row gap, and the subgrid inherits it.

01:57 You can override it. Give the card a row gap of the small space the badges use between them. Inside every card, that space drops to 9 pixels.

02:09 Last, a fourth child. Riverside Lido is closed on Saturday for a swim meet. In the Elements panel, edit the Lido card as HTML, and add a paragraph after the badges: Closed Saturday for the swim meet.

02:23 The card still spans three rows. Your turn: pause the video and predict where the note lands.

02:32 It lands in the third row, on top of the badges. The card’s subgrid has three rows, and a subgrid can’t add a row. This time there’s no free row left, so the note shares the last one.

02:44 It’s short, so the card doesn’t grow. Longer text would make that shared row taller, but never add a fourth.

02:52 Here’s the rule. A subgrid gets the tracks its item spans, in rows or columns, with their line names and their gap. In that direction it adds no tracks, and only its own children sit on them.

03:06 So when you write a subgrid, count the tracks the card spans and its children. More children than tracks, and the extras share the last one. Rosa’s cards line up, and now you can say why.

03:19 Next, in Exercise: Align the Pool Cards, you’ll line up a row of pool cards for Westbrook yourself.

Become a Member to join the conversation.