A presentation at NEDcamp in in Providence, RI, USA by Brian Perry
CSS is global by nature. Given the name, style sheets are intended to cascade and a single CSS rule could apply to multiple elements on your site. This is a powerful feature of CSS that can allow you to create consistent styling throughout your site with small amounts of code. But increasingly there are cases where front end developers want to instead scope their styles to a specific component and ensure that component styles are consistent and don’t impact other areas of the site.
This session will provide an overview of the various approaches to scoping CSS, both when using CSS alone, and when using CSS combined with JavaScript.
Starting from the perspective of CSS only approaches we’ll look at:
Next we’ll examine the various scoping approaches when using CSS in JavaScript, including:
Finally, we’ll wrap up by looking at a few ways that global and scoped CSS can be used together effectively.
The following resources were mentioned during the presentation or are useful additional information.
The following code examples from the presentation can be tried out live.
Here’s what was said about this presentation on social media.