CSS @scope

Back

CSS "Donut Scoping" using @scope

Allows CSS rules to be scoped to part of the document, with upper and lower limits described by selectors.
@scope (.card) to (.other-component) ❴
    // Styling goes here for .card (the donut) 
    // but does NOT apply to .other-component (hole of the donut)
❵
Using CSS @scope we only apply styles to the dark orange part displayed below
Donut scoping

Inspired by:

Donut styling explained

Example donuts

Scoping CSS also helps by not having to put HTML classes on every element! Just style the HTML element itself inside the @scope . Inspect the .card's HTML H2-element below.

Disco donuts

H2. Disco donuts

Amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati! Amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati!

H2. Other component

Styling not influenced by the card's CSS

Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati!

Read more
Chocolate donuts

H2. Chocolate donuts

Amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati!

H2. Other component

Styling not influenced by the card's CSS

Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati! Amet consectetur adipisicing elit.

Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati!

Read more
Sugar donuts

H2. Sugar donuts

Amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati!

H2. Other component

Styling not influenced by the card's CSS

Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia cum eius facere ut ad libero amet ex consequatur nostrum obcaecati!

Read more