Add a Compact Variant With a Style Query

In the sidebar, Rosa only wants what’s on next and when, but the Family badge, note, and full border make the card a tall box in a narrow column. She’d like a compact card there, while the Today panel keeps the full one.

You’ll switch the sidebar’s card to a compact variant with a style query, keep it readable where style queries aren’t supported, and check support yourself. Start with the switch.

Switch the Card From Its Slot

Both slots hold the same <article class="session-card">. A modifier class such as session-card--compact would work, but every sidebar card would need it. A style query lets the slot decide in CSS. It applies rules when a container’s custom property holds a given value.

In the components layer of styles.css, give the .sidebar rule the switch:

Language: CSS Filename: styles.css
.sidebar {
  --variant: compact;
  padding: var(--space-inset);
}

--variant is a name you choose, and it holds a word for your rules to test. Custom properties inherit, so everything inside the sidebar sees compact too.

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

Become a Member to join the conversation.