Loading
Animated Background Stripes Effect 12 exercises
solution

Create a Stacking Context to Make Text More Readable

To make any child element appear on top of the stripes, target the children selector - stripes > * - any element which is a child of stripes.


@layer components {
.stripes {
position: relative;
overflow: hidden;
}
.stripes > * {
isolation: isolate;
}
/* ... */
}

Loading solution

Transcript

0:00 All you need to do to make any child element appear on top of the stripes is target the children selector, so stripes > *, so any element which is a child of stripes. Here, we need to create a new stacking context. We could use position relative, but we'll be fancy here and use isolation isolate. This will explicitly create a new stacking context without any side effects.

0:22 Boom, you can see that now the text is in front of the stripe and therefore much more readable. This will only work for children elements, not the direct text node. If the button had just the text, you can see that that is not going to sit on top.

0:36 A little inconvenience is you always need to make sure that you have a wrapping element if you want something to appear on top of the stripes. In most cases that's going to be fine. If you have a button, it's good to know that you should wrap it in a span like that.